aboutsummaryrefslogtreecommitdiffstats
path: root/signer/core/validation.go
diff options
context:
space:
mode:
Diffstat (limited to 'signer/core/validation.go')
-rw-r--r--signer/core/validation.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/signer/core/validation.go b/signer/core/validation.go
index 288456df8..7c3ec4274 100644
--- a/signer/core/validation.go
+++ b/signer/core/validation.go
@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"math/big"
+ "regexp"
"github.com/ethereum/go-ethereum/common"
)
@@ -30,16 +31,6 @@ import (
// - Transaction semantics validation
// The package provides warnings for typical pitfalls
-func (vs *ValidationMessages) crit(msg string) {
- vs.Messages = append(vs.Messages, ValidationInfo{"CRITICAL", msg})
-}
-func (vs *ValidationMessages) warn(msg string) {
- vs.Messages = append(vs.Messages, ValidationInfo{"WARNING", msg})
-}
-func (vs *ValidationMessages) info(msg string) {
- vs.Messages = append(vs.Messages, ValidationInfo{"Info", msg})
-}
-
type Validator struct {
db *AbiDb
}
@@ -72,6 +63,9 @@ func (v *Validator) validateCallData(msgs *ValidationMessages, data []byte, meth
msgs.warn("Tx contains data which is not valid ABI")
return
}
+ if arglen := len(data) - 4; arglen%32 != 0 {
+ msgs.warn(fmt.Sprintf("Not ABI-encoded data; length should be a multiple of 32 (was %d)", arglen))
+ }
var (
info *decodedCallData
err error
@@ -161,3 +155,17 @@ func (v *Validator) ValidateTransaction(txArgs *SendTxArgs, methodSelector *stri
msgs := &ValidationMessages{}
return msgs, v.validate(msgs, txArgs, methodSelector)
}
+
+var Printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ]+$")
+
+// ValidatePasswordFormat returns an error if the password is too short, or consists of characters
+// outside the range of the printable 7bit ascii set
+func ValidatePasswordFormat(password string) error {
+ if len(password) < 10 {
+ return errors.New("password too short (<10 characters)")
+ }
+ if !Printable7BitAscii.MatchString(password) {
+ return errors.New("password contains invalid characters - only 7bit printable ascii allowed")
+ }
+ return nil
+}