aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-05-24 09:42:10 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-06-24 12:03:23 +0800
commitd23ec6c4194e7c0f70372db58d49ec222dc4e22c (patch)
tree7bc662eec5dd034873887088825761a94ce989af /common
parent22c7ce0162f2d14a7340e00e93697780c91d2087 (diff)
downloaddexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar
dexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.gz
dexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.bz2
dexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.lz
dexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.xz
dexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.zst
dexon-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.zip
Change keystore to version 3
* Change password protection crypto in keystore to version 3 * Update KeyStoreTests/basic_tests.json * Add support for PBKDF2 with HMAC-SHA256 * Change MAC and encryption key to avoid unnecessary hashing * Add tests for test vectors in new wiki page defining version 3 * Add tests for new keystore tests in ethereum/tests repo * Move JSON loading util to common for use in both tests and crypto packages * Add backwards compatibility with key store version 1
Diffstat (limited to 'common')
-rw-r--r--common/test_utils.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/test_utils.go b/common/test_utils.go
new file mode 100644
index 000000000..8346c147a
--- /dev/null
+++ b/common/test_utils.go
@@ -0,0 +1,37 @@
+package common
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+)
+
+// LoadJSON reads the given file and unmarshals its content.
+func LoadJSON(file string, val interface{}) error {
+ content, err := ioutil.ReadFile(file)
+ if err != nil {
+ return err
+ }
+ if err := json.Unmarshal(content, val); err != nil {
+ if syntaxerr, ok := err.(*json.SyntaxError); ok {
+ line := findLine(content, syntaxerr.Offset)
+ return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err)
+ }
+ return fmt.Errorf("JSON unmarshal error in %v: %v", file, err)
+ }
+ return nil
+}
+
+// findLine returns the line number for the given offset into data.
+func findLine(data []byte, offset int64) (line int) {
+ line = 1
+ for i, r := range string(data) {
+ if int64(i) >= offset {
+ return
+ }
+ if r == '\n' {
+ line++
+ }
+ }
+ return
+}