func TestKey(t *testing.T) { for i, v := range good { err := setConfig(len(v.output), len(v.salt), v.N, v.r, v.p) if err != nil { t.Errorf("%d: unexpected error setting config: %s", i, err) } setSalt(v.salt) encoded, err := mcf.Create(v.password) if err != nil { t.Errorf("%d: got unexpected error: %s", i, err) } passwd := password.New([]byte("scrypt")) err = passwd.Parse([]byte(encoded)) if err != nil { t.Errorf("%d: unexpected error creating password instance: %s", err) } if !bytes.Equal(passwd.Salt, []byte(v.salt)) { t.Errorf("%d: salt: expected %s, got %s", i, v.salt, string(passwd.Salt)) } if !bytes.Equal(passwd.Key, v.output) { t.Errorf("%d: expected %x, got %x", i, v.output, passwd.Key) } } for i, v := range bad { err := setConfig(32, len(v.salt), v.N, v.r, v.p) if err == nil { t.Errorf("%d: expected error, got nil", i) } setSalt(v.salt) _, err = mcf.Create(v.password) if err == nil { t.Errorf("%d: expected error, got nil", i) } } }
func (a *Account) SetPassword(password []byte) error { encrypted, err := mcf.Create(password) if err != nil { return err } a.Password = encrypted a.DateModified = time.Now() return nil }
func roundTrip(t *testing.T, plaintext string) { encoded, err := mcf.Create(plaintext) if err != nil { t.Fatal(err) } ok, err := mcf.Verify(plaintext, encoded) if err != nil { t.Fatal(err) } if !ok { t.Fatalf("Verify(%q, %q) failed", plaintext, encoded) } }