Fix noinlineerr findings: internal/crypto (refs #61)
This commit is contained in:
@@ -62,12 +62,14 @@ func (e *Encryptor) Encrypt(data []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write data
|
// Write data
|
||||||
if _, err := w.Write(data); err != nil {
|
_, err = w.Write(data)
|
||||||
|
if err != nil {
|
||||||
return nil, fmt.Errorf("writing encrypted data: %w", err)
|
return nil, fmt.Errorf("writing encrypted data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close to flush
|
// Close to flush
|
||||||
if err := w.Close(); err != nil {
|
err = w.Close()
|
||||||
|
if err != nil {
|
||||||
return nil, fmt.Errorf("closing encrypted writer: %w", err)
|
return nil, fmt.Errorf("closing encrypted writer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,12 +92,14 @@ func (e *Encryptor) EncryptStream(dst io.Writer, src io.Reader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy data
|
// Copy data
|
||||||
if _, err := io.Copy(w, src); err != nil {
|
_, err = io.Copy(w, src)
|
||||||
|
if err != nil {
|
||||||
return fmt.Errorf("copying encrypted data: %w", err)
|
return fmt.Errorf("copying encrypted data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close to flush
|
// Close to flush
|
||||||
if err := w.Close(); err != nil {
|
err = w.Close()
|
||||||
|
if err != nil {
|
||||||
return fmt.Errorf("closing encrypted writer: %w", err)
|
return fmt.Errorf("closing encrypted writer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ func TestEncryptor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var decrypted bytes.Buffer
|
var decrypted bytes.Buffer
|
||||||
if _, err := decrypted.ReadFrom(r); err != nil {
|
|
||||||
|
_, err = decrypted.ReadFrom(r)
|
||||||
|
if err != nil {
|
||||||
t.Fatalf("failed to read decrypted data: %v", err)
|
t.Fatalf("failed to read decrypted data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +101,9 @@ func TestEncryptorMultipleRecipients(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var decrypted bytes.Buffer
|
var decrypted bytes.Buffer
|
||||||
if _, err := decrypted.ReadFrom(r); err != nil {
|
|
||||||
|
_, err = decrypted.ReadFrom(r)
|
||||||
|
if err != nil {
|
||||||
t.Fatalf("recipient %d failed to read decrypted data: %v", i+1, err)
|
t.Fatalf("recipient %d failed to read decrypted data: %v", i+1, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +136,8 @@ func TestEncryptorUpdateRecipients(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update to second key
|
// Update to second key
|
||||||
if err := enc.UpdateRecipients([]string{publicKey2}); err != nil {
|
err = enc.UpdateRecipients([]string{publicKey2})
|
||||||
|
if err != nil {
|
||||||
t.Fatalf("failed to update recipients: %v", err)
|
t.Fatalf("failed to update recipients: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,20 +148,24 @@ func TestEncryptorUpdateRecipients(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First ciphertext should only decrypt with first identity
|
// First ciphertext should only decrypt with first identity
|
||||||
if _, err := age.Decrypt(bytes.NewReader(ciphertext1), identity1); err != nil {
|
_, err = age.Decrypt(bytes.NewReader(ciphertext1), identity1)
|
||||||
|
if 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 {
|
_, err = age.Decrypt(bytes.NewReader(ciphertext1), identity2)
|
||||||
|
if err == nil {
|
||||||
t.Error("should not decrypt with identity2")
|
t.Error("should not decrypt with identity2")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second ciphertext should only decrypt with second identity
|
// Second ciphertext should only decrypt with second identity
|
||||||
if _, err := age.Decrypt(bytes.NewReader(ciphertext2), identity2); err != nil {
|
_, err = age.Decrypt(bytes.NewReader(ciphertext2), identity2)
|
||||||
|
if 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 {
|
_, err = age.Decrypt(bytes.NewReader(ciphertext2), identity1)
|
||||||
|
if err == nil {
|
||||||
t.Error("should not decrypt with identity1")
|
t.Error("should not decrypt with identity1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user