mirror of
https://github.com/FiloSottile/age.git
synced 2026-03-11 08:55:41 +00:00
age,plugin: wrap more errors
This commit is contained in:
parent
0d5b598cd0
commit
bfae75d93d
2 changed files with 9 additions and 5 deletions
10
age.go
10
age.go
|
|
@ -137,7 +137,7 @@ func Encrypt(dst io.Writer, recipients ...Recipient) (io.WriteCloser, error) {
|
||||||
for i, r := range recipients {
|
for i, r := range recipients {
|
||||||
stanzas, l, err := wrapWithLabels(r, fileKey)
|
stanzas, l, err := wrapWithLabels(r, fileKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to wrap key for recipient #%d: %v", i, err)
|
return nil, fmt.Errorf("failed to wrap key for recipient #%d: %w", i, err)
|
||||||
}
|
}
|
||||||
sort.Strings(l)
|
sort.Strings(l)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
|
@ -155,7 +155,7 @@ func Encrypt(dst io.Writer, recipients ...Recipient) (io.WriteCloser, error) {
|
||||||
hdr.MAC = mac
|
hdr.MAC = mac
|
||||||
}
|
}
|
||||||
if err := hdr.Marshal(dst); err != nil {
|
if err := hdr.Marshal(dst); err != nil {
|
||||||
return nil, fmt.Errorf("failed to write header: %v", err)
|
return nil, fmt.Errorf("failed to write header: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
nonce := make([]byte, streamNonceSize)
|
nonce := make([]byte, streamNonceSize)
|
||||||
|
|
@ -163,7 +163,7 @@ func Encrypt(dst io.Writer, recipients ...Recipient) (io.WriteCloser, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := dst.Write(nonce); err != nil {
|
if _, err := dst.Write(nonce); err != nil {
|
||||||
return nil, fmt.Errorf("failed to write nonce: %v", err)
|
return nil, fmt.Errorf("failed to write nonce: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream.NewWriter(streamKey(fileKey, nonce), dst)
|
return stream.NewWriter(streamKey(fileKey, nonce), dst)
|
||||||
|
|
@ -210,6 +210,10 @@ func (*NoIdentityMatchError) Error() string {
|
||||||
return "no identity matched any of the recipients"
|
return "no identity matched any of the recipients"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *NoIdentityMatchError) Unwrap() []error {
|
||||||
|
return e.Errors
|
||||||
|
}
|
||||||
|
|
||||||
// Decrypt decrypts a file encrypted to one or more identities.
|
// Decrypt decrypts a file encrypted to one or more identities.
|
||||||
//
|
//
|
||||||
// It returns a Reader reading the decrypted plaintext of the age file read
|
// It returns a Reader reading the decrypted plaintext of the age file read
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func (r *Recipient) WrapWithLabels(fileKey []byte) (stanzas []*age.Stanza, label
|
||||||
|
|
||||||
conn, err := openClientConnection(r.name, "recipient-v1")
|
conn, err := openClientConnection(r.name, "recipient-v1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("couldn't start plugin: %v", err)
|
return nil, nil, fmt.Errorf("couldn't start plugin: %w", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ func (i *Identity) Unwrap(stanzas []*age.Stanza) (fileKey []byte, err error) {
|
||||||
|
|
||||||
conn, err := openClientConnection(i.name, "identity-v1")
|
conn, err := openClientConnection(i.name, "identity-v1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't start plugin: %v", err)
|
return nil, fmt.Errorf("couldn't start plugin: %w", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue