@@ -10,8 +10,10 @@ import (
1010 "io"
1111 "os"
1212 "path"
13+ "strings"
1314
1415 "filippo.io/age"
16+ "filippo.io/age/agessh"
1517 "github.com/ProtonMail/go-crypto/openpgp/armor"
1618 openpgp "github.com/ProtonMail/go-crypto/openpgp/v2"
1719 "github.com/offen/docker-volume-backup/internal/errwrap"
@@ -73,7 +75,7 @@ func (s *script) getConfiguredAgeRecipients() ([]age.Recipient, error) {
7375 recipients := []age.Recipient {}
7476 if len (s .c .AgePublicKeys ) > 0 {
7577 for _ , pk := range s .c .AgePublicKeys {
76- pkr , err := age . ParseX25519Recipient (pk )
78+ pkr , err := parseAgeRecipient (pk )
7779 if err != nil {
7880 return nil , errwrap .Wrap (err , "failed to parse age public key" )
7981 }
@@ -94,6 +96,18 @@ func (s *script) getConfiguredAgeRecipients() ([]age.Recipient, error) {
9496 return recipients , nil
9597}
9698
99+ func parseAgeRecipient (arg string ) (age.Recipient , error ) {
100+ // This logic is adapted from what the age CLI is doing
101+ // stripping some special cases
102+ switch {
103+ case strings .HasPrefix (arg , "age1" ):
104+ return age .ParseX25519Recipient (arg )
105+ case strings .HasPrefix (arg , "ssh-" ):
106+ return agessh .ParseRecipient (arg )
107+ }
108+ return nil , fmt .Errorf ("unknown recipient type: %q" , arg )
109+ }
110+
97111func (s * script ) encryptWithAge (rec []age.Recipient ) error {
98112 return s .doEncrypt ("age" , func (ciphertextWriter io.Writer ) (io.WriteCloser , error ) {
99113 return age .Encrypt (ciphertextWriter , rec ... )
0 commit comments