/** Only accepts <code>Gmss512PrivateKey</code>s. */ @Override public byte[] sign(byte[] data, PrivateKey key, KeyUpdateHandler keyUpdateHandler) throws GeneralSecurityException, PasswordException { Gmss512PrivateKey gmssKey = castToGMSS(key); GMSSSignature signer = new GMSSSignature.GMSSwithSHA512(); signer.initSign(gmssKey.key); signer.update(data); byte[] signature = signer.sign(); try { keyUpdateHandler.updateKey(); } catch (IOException e) { throw new KeyStoreException("Error updating GMSS key after signing.", e); } return signature; }
/** Returns a <code>KeyUpdateHandler</code> that must be called exactly <code>numExpectedCalls</code> times */ public static KeyUpdateHandler createVerifyingKeyUpdateHandler(final int numExpectedCalls) throws GeneralSecurityException, IOException, PasswordException { Mockery mockery = new Mockery(); final KeyUpdateHandler keyUpdateHandler = mockery.mock(KeyUpdateHandler.class); mockery.checking(new Expectations() {{ exactly(numExpectedCalls).of(keyUpdateHandler).updateKey(); }}); return keyUpdateHandler; }