@@ -183,17 +183,21 @@ else if (basePubKey instanceof ECPublicBCPGKey)
183183 pubKey = new PGPPublicKey (pubPacket , fingerPrintCalculator );
184184 }
185185 secretKeyPacket = getSecKeyPacket (pubKey , keyProtectionRemoverFactory , maxDepth , type , expression , digestProvider , eccLabels ,
186- keyIn ->
186+ new GetSecKeyDataOperation ()
187187 {
188- BigInteger d = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("d" ).getBytes (1 ));
189- final String curve = expression .getExpressionWithLabel ("curve" ).getString (1 );
190- if (curve .startsWith ("NIST" ) || curve .startsWith ("brain" ))
188+ @ Override
189+ public byte [] getSecKeyData (SExpression keyIn )
191190 {
192- return new ECSecretBCPGKey (d ).getEncoded ();
193- }
194- else
195- {
196- return new EdSecretBCPGKey (d ).getEncoded ();
191+ BigInteger d = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("d" ).getBytes (1 ));
192+ final String curve = expression .getExpressionWithLabel ("curve" ).getString (1 );
193+ if (curve .startsWith ("NIST" ) || curve .startsWith ("brain" ))
194+ {
195+ return new ECSecretBCPGKey (d ).getEncoded ();
196+ }
197+ else
198+ {
199+ return new EdSecretBCPGKey (d ).getEncoded ();
200+ }
197201 }
198202 });
199203 }
@@ -219,10 +223,15 @@ public void assertPublicKeyMatch(BCPGKey k1, BCPGKey k2)
219223 }
220224 });
221225 secretKeyPacket = getSecKeyPacket (pubKey , keyProtectionRemoverFactory , maxDepth , type , expression , digestProvider , dsaLabels ,
222- keyIn ->
226+ new GetSecKeyDataOperation ()
223227 {
224- BigInteger x = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("x" ).getBytes (1 ));
225- return new DSASecretBCPGKey (x ).getEncoded ();
228+ @ Override
229+ public byte [] getSecKeyData (SExpression keyIn )
230+ {
231+ BigInteger x = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("x" ).getBytes (1 ));
232+
233+ return new DSASecretBCPGKey (x ).getEncoded ();
234+ }
226235 });
227236 }
228237 else if (keyType .equals ("elg" ))
@@ -246,10 +255,15 @@ public void assertPublicKeyMatch(BCPGKey k1, BCPGKey k2)
246255 }
247256 });
248257 secretKeyPacket = getSecKeyPacket (pubKey , keyProtectionRemoverFactory , maxDepth , type , expression , digestProvider , elgLabels ,
249- keyIn ->
258+ new GetSecKeyDataOperation ()
250259 {
251- BigInteger x = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("x" ).getBytes (1 ));
252- return new ElGamalSecretBCPGKey (x ).getEncoded ();
260+ @ Override
261+ public byte [] getSecKeyData (SExpression keyIn )
262+ {
263+ BigInteger x = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("x" ).getBytes (1 ));
264+
265+ return new ElGamalSecretBCPGKey (x ).getEncoded ();
266+ }
253267 });
254268 }
255269 else if (keyType .equals ("rsa" ))
@@ -275,12 +289,16 @@ public void assertPublicKeyMatch(BCPGKey k1, BCPGKey k2)
275289 }
276290 });
277291 secretKeyPacket = getSecKeyPacket (pubKey , keyProtectionRemoverFactory , maxDepth , type , expression , digestProvider , rsaLabels ,
278- keyIn ->
292+ new GetSecKeyDataOperation ()
279293 {
280- BigInteger d = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("d" ).getBytes (1 ));
281- BigInteger p = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("p" ).getBytes (1 ));
282- BigInteger q = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("q" ).getBytes (1 ));
283- return new RSASecretBCPGKey (d , p , q ).getEncoded ();
294+ @ Override
295+ public byte [] getSecKeyData (SExpression keyIn )
296+ {
297+ BigInteger d = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("d" ).getBytes (1 ));
298+ BigInteger p = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("p" ).getBytes (1 ));
299+ BigInteger q = BigIntegers .fromUnsignedByteArray (keyIn .getExpressionWithLabelOrFail ("q" ).getBytes (1 ));
300+ return new RSASecretBCPGKey (d , p , q ).getEncoded ();
301+ }
284302 });
285303 }
286304 else
@@ -340,14 +358,14 @@ private static PGPPublicKey getPublicKey(KeyFingerPrintCalculator fingerPrintCal
340358 return pubKey ;
341359 }
342360
343- private interface getSecKeyDataOperation
361+ private interface GetSecKeyDataOperation
344362 {
345363 byte [] getSecKeyData (SExpression keyIn );
346364 }
347365
348366 private static SecretKeyPacket getSecKeyPacket (PGPPublicKey pubKey , PBEProtectionRemoverFactory keyProtectionRemoverFactory , int maxDepth , int type ,
349367 SExpression expression , PGPDigestCalculatorProvider digestProvider ,
350- Map <Integer , String []> labels , getSecKeyDataOperation operation )
368+ Map <Integer , String []> labels , GetSecKeyDataOperation operation )
351369 throws PGPException , IOException
352370 {
353371 byte [] secKeyData = null ;
0 commit comments