use of org.apache.harmony.security.tests.support.PublicKeyStub in project robovm by robovm.
the class SignerTest method testGetPrivateKey.
/**
* verify Signer.getPrivateKey() returns null or private key
*/
public void testGetPrivateKey() throws Exception {
byte[] privateKeyData = { 1, 2, 3, 4, 5 };
PrivateKeyStub privateKey = new PrivateKeyStub("private", "fff", privateKeyData);
PublicKeyStub publicKey = new PublicKeyStub("public", "fff", null);
KeyPair kp = new KeyPair(publicKey, privateKey);
Signer s = new SignerStub("sss5");
assertNull(s.getPrivateKey());
s.setKeyPair(kp);
assertSame(privateKey, s.getPrivateKey());
}
use of org.apache.harmony.security.tests.support.PublicKeyStub in project robovm by robovm.
the class SignerTest method test_toString.
/**
* java.security.Signer#toString()
*/
public void test_toString() throws Exception {
Signer s1 = new SignerStub("testToString1");
assertEquals("[Signer]testToString1", s1.toString());
Signer s2 = new SignerStub("testToString2", IdentityScope.getSystemScope());
s2.toString();
KeyPair kp = new KeyPair(new PublicKeyStub("public", "SignerTest.testToString", null), new PrivateKeyStub("private", "SignerTest.testToString", null));
s1.setKeyPair(kp);
s1.toString();
s2.setKeyPair(kp);
s2.toString();
}
use of org.apache.harmony.security.tests.support.PublicKeyStub in project robovm by robovm.
the class IdentityTest method testGetPublicKey.
/**
* verify Identity.getPublicKey() returns public key
*/
public void testGetPublicKey() throws Exception {
Identity i = new IdentityStub("testGetPublicKey");
assertNull(i.getPublicKey());
PublicKey pk = new PublicKeyStub("kkk", "Identity.testGetPublicKey", null);
i.setPublicKey(pk);
assertSame(pk, i.getPublicKey());
}
use of org.apache.harmony.security.tests.support.PublicKeyStub in project robovm by robovm.
the class IdentityTest method testCertificates.
//
// Commented out since there will no be fix for the test failure
// /**
// * verify removeCertificate(Certificate certificate) removes certificate
// */
// public void testRemoveCertificate1() throws Exception{
// Identity i = new IdentityStub("iii");
// PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
// CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
// i.addCertificate(c1);
// assertSame(c1, i.certificates()[0]);
// i.removeCertificate(c1);
// assertEquals(0, i.certificates().length);
// // throw KeyManagementException if certificate not found
// try {
// i.removeCertificate(c1);
// fail("KeyManagementException should be thrown");
// } catch (KeyManagementException ok) {
// }
// try {
// i.removeCertificate(null);
// fail("KeyManagementException should be thrown");
// } catch (KeyManagementException ok) {
//
// }
// }
/**
* verify certificates() returns a copy of all certificates for this identity
*/
public void testCertificates() throws Exception {
Identity i = new IdentityStub("iii");
PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
CertificateStub c2 = new CertificateStub("zzz", null, null, pk1);
i.addCertificate(c1);
i.addCertificate(c2);
java.security.Certificate[] s = i.certificates();
assertEquals(2, s.length);
assertTrue(c1.equals(s[0]) || c2.equals(s[0]));
assertTrue(c1.equals(s[1]) || c2.equals(s[1]));
s[0] = null;
s[1] = null;
// check that the copy was modified
s = i.certificates();
assertEquals(2, s.length);
assertTrue(c1.equals(s[0]) || c2.equals(s[0]));
assertTrue(c1.equals(s[1]) || c2.equals(s[1]));
}
Aggregations