use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey in project popstellar by dedis.
the class PrivateKeyTest method badKeyFailsAtConstruction.
@Test
public void badKeyFailsAtConstruction() throws GeneralSecurityException {
assertThrows(IllegalArgumentException.class, () -> new PlainPrivateKey(new byte[] { 0, 1, 2 }));
KeysetHandle keyset = mock(KeysetHandle.class);
when(keyset.getPrimitive(PublicKeySign.class)).thenThrow(new GeneralSecurityException());
assertThrows(IllegalArgumentException.class, () -> new ProtectedPrivateKey(keyset));
}
use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey in project popstellar by dedis.
the class PrivateKeyTest method signGivesExpectedValue.
@Test
public void signGivesExpectedValue() throws GeneralSecurityException {
PrivateKey key = new PlainPrivateKey(VALID_PRIVATE_KEY);
Signature sign = key.sign(DATA);
assertEquals(EXPECTED_SIGNATURE, sign);
}
use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey in project popstellar by dedis.
the class PrivateKeyTest method signGivesSameValueForBothKeyType.
@Test
public void signGivesSameValueForBothKeyType() throws GeneralSecurityException {
PrivateKey key1 = new PlainPrivateKey(VALID_PRIVATE_KEY);
KeysetHandle keyset = mock(KeysetHandle.class);
when(keyset.getPrimitive(PublicKeySign.class)).thenReturn(new Ed25519Sign(VALID_PRIVATE_KEY));
PrivateKey key2 = new ProtectedPrivateKey(keyset);
Signature sign1 = key1.sign(DATA);
Signature sign2 = key2.sign(DATA);
assertEquals(sign1, sign2);
}
use of com.github.dedis.popstellar.model.objects.security.privatekey.PlainPrivateKey in project popstellar by dedis.
the class PrivateKeyTest method privateKeyHidesValueInStringRepresentation.
@Test
public void privateKeyHidesValueInStringRepresentation() {
PlainPrivateKey key = new PlainPrivateKey(VALID_PRIVATE_KEY);
assertFalse(key.toString().contains(key.getEncoded()));
}
Aggregations