@@ -144,26 +144,31 @@ func AddGPGKey(ownerID int64, content string) (*GPGKey, error) {
144
144
145
145
return key , sess .Commit ()
146
146
}
147
- func base64EncPubKey (pubkey * packet.PublicKey ) string {
147
+ func base64EncPubKey (pubkey * packet.PublicKey ) ( string , error ) {
148
148
var w bytes.Buffer
149
- if err := pubkey .Serialize (& w ); err != nil {
150
- log .Warn ("Failed to serialize public key content: %v" , pubkey .Fingerprint )
149
+ err := pubkey .Serialize (& w )
150
+ if err != nil {
151
+ return "" , err
151
152
}
152
- return base64 .StdEncoding .EncodeToString (w .Bytes ())
153
+ return base64 .StdEncoding .EncodeToString (w .Bytes ()), nil
153
154
}
154
- func parseSubGPGKey (ownerID int64 , primaryID string , pubkey * packet.PublicKey , expiry time.Time ) * GPGKey {
155
+ func parseSubGPGKey (ownerID int64 , primaryID string , pubkey * packet.PublicKey , expiry time.Time ) (* GPGKey , error ) {
156
+ content , err := base64EncPubKey (pubkey )
157
+ if err != nil {
158
+ return nil , err
159
+ }
155
160
return & GPGKey {
156
161
OwnerID : ownerID ,
157
162
KeyID : pubkey .KeyIdString (),
158
163
PrimaryKeyID : primaryID ,
159
- Content : base64EncPubKey ( pubkey ) ,
164
+ Content : content ,
160
165
Created : pubkey .CreationTime ,
161
166
Expired : expiry ,
162
167
CanSign : pubkey .CanSign (),
163
168
CanEncryptComms : pubkey .PubKeyAlgo .CanEncrypt (),
164
169
CanEncryptStorage : pubkey .PubKeyAlgo .CanEncrypt (),
165
170
CanCertify : pubkey .PubKeyAlgo .CanSign (),
166
- }
171
+ }, nil
167
172
}
168
173
func parseGPGKey (ownerID int64 , e * openpgp.Entity ) (* GPGKey , error ) {
169
174
pubkey := e .PrimaryKey
@@ -186,7 +191,11 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
186
191
//Parse Subkeys
187
192
subkeys := make ([]* GPGKey , len (e .Subkeys ))
188
193
for i , k := range e .Subkeys {
189
- subkeys [i ] = parseSubGPGKey (ownerID , pubkey .KeyIdString (), k .PublicKey , expiry )
194
+ subs , err := parseSubGPGKey (ownerID , pubkey .KeyIdString (), k .PublicKey , expiry )
195
+ if err != nil {
196
+ return nil , err
197
+ }
198
+ subkeys [i ] = subs
190
199
}
191
200
192
201
//Check emails
@@ -209,12 +218,15 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
209
218
}
210
219
n ++
211
220
}
212
-
221
+ content , err := base64EncPubKey (pubkey )
222
+ if err != nil {
223
+ return nil , err
224
+ }
213
225
return & GPGKey {
214
226
OwnerID : ownerID ,
215
227
KeyID : pubkey .KeyIdString (),
216
228
PrimaryKeyID : "" ,
217
- Content : base64EncPubKey ( pubkey ) ,
229
+ Content : content ,
218
230
Created : pubkey .CreationTime ,
219
231
Expired : expiry ,
220
232
Emails : emails ,
0 commit comments