@@ -90,17 +90,40 @@ func processRecipientKeys(recipients []string) ([][]byte, [][]byte, [][]byte, er
9090 x509s [][]byte
9191 )
9292 for _ , recipient := range recipients {
93- tmp , err := ioutil . ReadFile ( recipient )
94- if err != nil {
95- gpgRecipients = append ( gpgRecipients , [] byte ( recipient ))
96- continue
93+
94+ idx := strings . Index ( recipient , ":" )
95+ if idx < 0 {
96+ return nil , nil , nil , errors . New ( "Invalid recipient format" )
9797 }
98- if encutils .IsCertificate (tmp ) {
99- x509s = append (x509s , tmp )
100- } else if encutils .IsPublicKey (tmp ) {
98+
99+ protocol := recipient [:idx ]
100+ value := recipient [idx + 1 :]
101+
102+ switch protocol {
103+ case "pgp" :
104+ gpgRecipients = append (gpgRecipients , []byte (value ))
105+ case "jwe" :
106+ tmp , err := ioutil .ReadFile (value )
107+ if err != nil {
108+ return nil , nil , nil , errors .Wrap (err , "Unable to read file" )
109+ }
110+ if ! encutils .IsPublicKey (tmp ) {
111+ return nil , nil , nil , errors .New ("File provided is not a public key" )
112+ }
101113 pubkeys = append (pubkeys , tmp )
102- } else {
103- gpgRecipients = append (gpgRecipients , []byte (recipient ))
114+
115+ case "pkcs7" :
116+ tmp , err := ioutil .ReadFile (value )
117+ if err != nil {
118+ return nil , nil , nil , errors .Wrap (err , "Unable to read file" )
119+ }
120+ if ! encutils .IsCertificate (tmp ) {
121+ return nil , nil , nil , errors .New ("File provided is not an x509 cert" )
122+ }
123+ x509s = append (x509s , tmp )
124+
125+ default :
126+ return nil , nil , nil , errors .New ("Provided protocol not recognized" )
104127 }
105128 }
106129 return gpgRecipients , pubkeys , x509s , nil
0 commit comments