Skip to content

Commit

Permalink
V3 fixes (#21)
Browse files Browse the repository at this point in the history
Added missing functions
  • Loading branch information
Scratch-net authored Mar 26, 2020
1 parent 5b3d1d1 commit c062c1c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ linters:
- goconst
- gosimple
- gocyclo
- gofmt
- nakedret
- misspell
- gosec
Expand All @@ -199,7 +198,6 @@ linters:
- prealloc
- gocritic
- depguard
- stylecheck

# - dupl
# - wsl
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: go
go:
- stable
- tip

services: mysql

Expand Down
14 changes: 7 additions & 7 deletions protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestPure_EncryptDecrypt(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, res)

ciphertext, err := p.encrypt(userName, dataID, nil, nil, nil, []byte(plaintext))
ciphertext, err := p.EncryptGeneral(userName, dataID, nil, nil, nil, []byte(plaintext))
require.NoError(t, err)
decrypted, err := p.Decrypt(res.Grant, userName, dataID, ciphertext)
require.NoError(t, err)
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestPure_EncryptDecrypt_Share_Unshare_Admin_ChangePassword(t *testing.T) {
kp, err := p.PureCrypto.GenerateUserKey()
require.NoError(t, err)

ciphertext, err := p.encrypt(userId1, dataId, nil, nil, []crypto.PublicKey{kp.PublicKey()}, []byte(plaintext))
ciphertext, err := p.EncryptGeneral(userId1, dataId, nil, nil, []crypto.PublicKey{kp.PublicKey()}, []byte(plaintext))
require.NoError(t, err)

err = p.Share(res1.Grant, dataId, []string{userId2}, nil)
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestPure_CreateUserGrantAsAdmin(t *testing.T) {
err = p.RegisterUser(userId, password)
require.NoError(t, err)

ciphertext, err := p.encrypt(userId, dataId, nil, nil, nil, text)
ciphertext, err := p.EncryptGeneral(userId, dataId, nil, nil, nil, text)
require.NoError(t, err)

grant, err := p.CreateUserGrantAsAdmin(userId, bupk, DefaultGrantTTL)
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestPure_Roles(t *testing.T) {
require.NoError(t, err)

//user1 encrypts to role
ciphertext, err := p.encrypt(userId1, dataId, nil, []string{roleName}, nil, []byte(plaintext))
ciphertext, err := p.EncryptGeneral(userId1, dataId, nil, []string{roleName}, nil, []byte(plaintext))
require.NoError(t, err)

decrypted1, err := p.Decrypt(res1.Grant, "", dataId, ciphertext)
Expand Down Expand Up @@ -698,7 +698,7 @@ func TestPure_DeleteUser_cascade(t *testing.T) {
err = p.RegisterUser(userName, password)
require.NoError(t, err)

ciphertext, err := p.encrypt(userName, dataID, nil, nil, nil, []byte(plaintext))
ciphertext, err := p.EncryptGeneral(userName, dataID, nil, nil, nil, []byte(plaintext))
require.NoError(t, err)

res, err := p.AuthenticateUser(userName, password, nil)
Expand Down Expand Up @@ -734,7 +734,7 @@ func TestPure_DeleteUser_nocascade(t *testing.T) {
err = p.RegisterUser(userName, password)
require.NoError(t, err)

ciphertext, err := p.encrypt(userName, dataID, nil, nil, nil, []byte(plaintext))
ciphertext, err := p.EncryptGeneral(userName, dataID, nil, nil, nil, []byte(plaintext))
require.NoError(t, err)

res, err := p.AuthenticateUser(userName, password, nil)
Expand Down Expand Up @@ -770,7 +770,7 @@ func TestPure_RecoverUser(t *testing.T) {
err = p.RegisterUser(userName, password)
require.NoError(t, err)

ciphertext, err := p.encrypt(userName, dataID, nil, nil, nil, []byte(plaintext))
ciphertext, err := p.EncryptGeneral(userName, dataID, nil, nil, nil, []byte(plaintext))
require.NoError(t, err)

require.NoError(t, p.RecoverUser(userName, password2))
Expand Down
17 changes: 14 additions & 3 deletions pure.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ func (p *Pure) DeleteUser(userID string, cascade bool) error {
return p.Storage.DeleteUser(userID, cascade)
}

func (p *Pure) ResetUser(userID, newPassword string, cascade bool) error {
if err := p.DeleteUser(userID, cascade); err != nil {
return err
}
return p.RegisterUser(userID, newPassword)
}

func (p *Pure) DeleteKey(userID, dataID string) error {
return p.Storage.DeleteCellKey(userID, dataID)
}

func (p *Pure) PerformRotation() (*RotationResults, error) {
if p.CurrentVersion <= 1 {
return &RotationResults{0, 0}, nil
Expand Down Expand Up @@ -288,11 +299,11 @@ func (p *Pure) PerformRotation() (*RotationResults, error) {
}

func (p *Pure) Encrypt(userID, dataID string, plaintext []byte) ([]byte, error) {
return p.encrypt(userID, dataID, nil, nil, nil, plaintext)
return p.EncryptGeneral(userID, dataID, nil, nil, nil, plaintext)
}

//nolint: gocyclo,gocritic
func (p *Pure) encrypt(
//nolint: golint,gocyclo,gocritic
func (p *Pure) EncryptGeneral(
userID, dataID string,
otherUserIDs []string,
roleNames []string,
Expand Down

0 comments on commit c062c1c

Please sign in to comment.