Apply linter autofixes: internal/crypto (refs #61)
This commit is contained in:
@@ -2,6 +2,7 @@ package crypto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -25,7 +26,7 @@ type Encryptor struct {
|
|||||||
// public keys are invalid or if no recipients are specified.
|
// public keys are invalid or if no recipients are specified.
|
||||||
func NewEncryptor(publicKeys []string) (*Encryptor, error) {
|
func NewEncryptor(publicKeys []string) (*Encryptor, error) {
|
||||||
if len(publicKeys) == 0 {
|
if len(publicKeys) == 0 {
|
||||||
return nil, fmt.Errorf("at least one recipient is required")
|
return nil, errors.New("at least one recipient is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
recipients := make([]age.Recipient, 0, len(publicKeys))
|
recipients := make([]age.Recipient, 0, len(publicKeys))
|
||||||
@@ -34,6 +35,7 @@ func NewEncryptor(publicKeys []string) (*Encryptor, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("parsing age recipient %s: %w", key, err)
|
return nil, fmt.Errorf("parsing age recipient %s: %w", key, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
recipients = append(recipients, recipient)
|
recipients = append(recipients, recipient)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +128,7 @@ func (e *Encryptor) EncryptWriter(dst io.Writer) (io.WriteCloser, error) {
|
|||||||
// of the public keys are invalid or if no recipients are specified.
|
// of the public keys are invalid or if no recipients are specified.
|
||||||
func (e *Encryptor) UpdateRecipients(publicKeys []string) error {
|
func (e *Encryptor) UpdateRecipients(publicKeys []string) error {
|
||||||
if len(publicKeys) == 0 {
|
if len(publicKeys) == 0 {
|
||||||
return fmt.Errorf("at least one recipient is required")
|
return errors.New("at least one recipient is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
recipients := make([]age.Recipient, 0, len(publicKeys))
|
recipients := make([]age.Recipient, 0, len(publicKeys))
|
||||||
@@ -135,6 +137,7 @@ func (e *Encryptor) UpdateRecipients(publicKeys []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("parsing age recipient %s: %w", key, err)
|
return fmt.Errorf("parsing age recipient %s: %w", key, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
recipients = append(recipients, recipient)
|
recipients = append(recipients, recipient)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,12 @@ func TestEncryptorMultipleRecipients(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate identity1: %v", err)
|
t.Fatalf("failed to generate identity1: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
identity2, err := age.GenerateX25519Identity()
|
identity2, err := age.GenerateX25519Identity()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate identity2: %v", err)
|
t.Fatalf("failed to generate identity2: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
identity3, err := age.GenerateX25519Identity()
|
identity3, err := age.GenerateX25519Identity()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to generate identity3: %v", err)
|
t.Fatalf("failed to generate identity3: %v", err)
|
||||||
@@ -123,6 +125,7 @@ func TestEncryptorUpdateRecipients(t *testing.T) {
|
|||||||
|
|
||||||
// Encrypt with first key
|
// Encrypt with first key
|
||||||
plaintext := []byte("test data")
|
plaintext := []byte("test data")
|
||||||
|
|
||||||
ciphertext1, err := enc.Encrypt(plaintext)
|
ciphertext1, err := enc.Encrypt(plaintext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to encrypt: %v", err)
|
t.Fatalf("failed to encrypt: %v", err)
|
||||||
@@ -143,6 +146,7 @@ func TestEncryptorUpdateRecipients(t *testing.T) {
|
|||||||
if _, err := age.Decrypt(bytes.NewReader(ciphertext1), identity1); err != nil {
|
if _, err := age.Decrypt(bytes.NewReader(ciphertext1), identity1); err != nil {
|
||||||
t.Error("failed to decrypt with identity1")
|
t.Error("failed to decrypt with identity1")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := age.Decrypt(bytes.NewReader(ciphertext1), identity2); err == nil {
|
if _, err := age.Decrypt(bytes.NewReader(ciphertext1), identity2); err == nil {
|
||||||
t.Error("should not decrypt with identity2")
|
t.Error("should not decrypt with identity2")
|
||||||
}
|
}
|
||||||
@@ -151,6 +155,7 @@ func TestEncryptorUpdateRecipients(t *testing.T) {
|
|||||||
if _, err := age.Decrypt(bytes.NewReader(ciphertext2), identity2); err != nil {
|
if _, err := age.Decrypt(bytes.NewReader(ciphertext2), identity2); err != nil {
|
||||||
t.Error("failed to decrypt with identity2")
|
t.Error("failed to decrypt with identity2")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := age.Decrypt(bytes.NewReader(ciphertext2), identity1); err == nil {
|
if _, err := age.Decrypt(bytes.NewReader(ciphertext2), identity1); err == nil {
|
||||||
t.Error("should not decrypt with identity1")
|
t.Error("should not decrypt with identity1")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user