本文整理汇总了Java中java.security.Identity.setPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java Identity.setPublicKey方法的具体用法?Java Identity.setPublicKey怎么用?Java Identity.setPublicKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.Identity
的用法示例。
在下文中一共展示了Identity.setPublicKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_addIdentityLjava_security_Identity
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#addIdentity(java.security.Identity)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "addIdentity",
args = {java.security.Identity.class}
)
public void test_addIdentityLjava_security_Identity() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass("id1");
id.setPublicKey(pubKey);
sub.addIdentity(id);
try {
Identity id2 = new IdentitySubclass("id2");
id2.setPublicKey(pubKey);
sub.addIdentity(id2);
fail("KeyManagementException should have been thrown");
} catch (KeyManagementException e) {
// Expected
}
}
示例2: test_removeIdentityLjava_security_Identity
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#removeIdentity(java.security.Identity)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "removeIdentity",
args = {java.security.Identity.class}
)
public void test_removeIdentityLjava_security_Identity() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
sub.removeIdentity(id);
try {
sub.removeIdentity(id);
fail("KeyManagementException should have been thrown");
} catch (KeyManagementException e) {
// expected
}
}
示例3: test_identities
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#identities()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "identities",
args = {}
)
public void test_identities() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
Enumeration<Identity> en = sub.identities();
assertTrue("Wrong object contained in identities", en.nextElement()
.equals(id));
assertTrue("Contains too many elements", !en.hasMoreElements());
}
示例4: test_getIdentityLjava_security_PublicKey
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#getIdentity(java.security.PublicKey)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "getIdentity",
args = {java.security.PublicKey.class}
)
public void test_getIdentityLjava_security_PublicKey() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
Identity returnedId = sub.getIdentity(pubKey);
assertEquals("Test 1: Returned Identity not the same as the added one;",
id, returnedId);
assertNull("Test 2: Null value expected.",
sub.getIdentity((PublicKey) null));
PublicKey anotherKey = KeyPairGenerator.getInstance("DSA").genKeyPair().getPublic();
assertNull("Test 3: Null value expected.",
sub.getIdentity(anotherKey));
}
示例5: test_getIdentityLjava_lang_String
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#getIdentity(java.lang.String)
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "getIdentity",
args = {java.lang.String.class}
)
public void test_getIdentityLjava_lang_String() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass("test");
id.setPublicKey(pubKey);
sub.addIdentity(id);
Identity returnedId = sub.getIdentity("test");
assertEquals("Returned Identity not the same as the added one", id,
returnedId);
}
示例6: test_toString
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#toString()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "toString",
args = {}
)
public void test_toString() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
assertNotNull("toString returned a null", sub.toString());
assertTrue("Not a valid String ", sub.toString().length() > 0);
}
示例7: testAddCertificate1
import java.security.Identity; //导入方法依赖的package包/类
/**
* verify addCertificate(Certificate certificate) adds a certificate for this identity.
* If the identity has a public key, the public key in the certificate must be the same
*
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "addCertificate",
args = {java.security.Certificate.class}
)
public void testAddCertificate1() throws Exception {
Identity i = new IdentityStub("iii");
PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", new byte[]{1,2,3,4,5});
i.setPublicKey(pk1);
// try with the same key
CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
i.addCertificate(c1);
assertSame(c1, i.certificates()[0]);
// try Certificate with different key
try {
i.addCertificate(new CertificateStub("ccc", null, null, new PublicKeyStub("k2", "fff", new byte[]{6,7,8,9,0})));
fail("KeyManagementException should be thrown");
} catch (KeyManagementException ok) {}
}
示例8: testSetPublicKey4
import java.security.Identity; //导入方法依赖的package包/类
/**
*
* verify Identity.setPublicKey() removes old key and all identity's certificates
*
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "setPublicKey",
args = {java.security.PublicKey.class}
)
public void testSetPublicKey4() throws Exception {
Identity i = new IdentityStub("testSetPublicKey4");
PublicKeyStub pk1 = new PublicKeyStub("kkk", "Identity.testSetPublicKey4", null);
CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
CertificateStub c2 = new CertificateStub("zzz", null, null, pk1);
i.addCertificate(c1);
i.addCertificate(c2);
assertEquals(2, i.certificates().length);
assertSame(pk1, i.getPublicKey());
PublicKeyStub pk2 = new PublicKeyStub("zzz", "Identity.testSetPublicKey4", null);
i.setPublicKey(pk2);
assertSame(pk2, i.getPublicKey());
assertEquals(0, i.certificates().length);
}
示例9: test_addIdentityLjava_security_Identity
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#addIdentity(java.security.Identity)
*/
public void test_addIdentityLjava_security_Identity() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass("id1");
id.setPublicKey(pubKey);
sub.addIdentity(id);
try {
Identity id2 = new IdentitySubclass("id2");
id2.setPublicKey(pubKey);
sub.addIdentity(id2);
fail("KeyManagementException should have been thrown");
} catch (KeyManagementException e) {
// Expected
}
}
示例10: test_size
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#size()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "size",
args = {}
)
public void test_size() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
assertEquals("Wrong size", 1, sub.size());
}
示例11: testIdentityEquals
import java.security.Identity; //导入方法依赖的package包/类
/**
* verify Identity.identityEquals(Identity) return true, only if names and public keys are equal
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "identityEquals",
args = {java.security.Identity.class}
)
public void testIdentityEquals() throws Exception {
String name = "nnn";
PublicKey pk = new PublicKeyStub("aaa", "fff", new byte[]{1,2,3,4,5});
IdentityStub i = new IdentityStub(name);
i.setPublicKey(pk);
Object[] value = {
//null, Boolean.FALSE,
//new Object(), Boolean.FALSE,
new IdentityStub("111"), Boolean.FALSE,
new IdentityStub(name), Boolean.FALSE,
new IdentityStub(name, IdentityScope.getSystemScope()), Boolean.FALSE,
i, Boolean.TRUE,
new IdentityStub(name, pk), Boolean.TRUE
};
for (int k=0; k<value.length; k+=2){
assertEquals(value[k+1], new Boolean(i.identityEquals((Identity)value[k])));
if (Boolean.TRUE.equals(value[k+1])) assertEquals(i.hashCode(), value[k].hashCode());
}
Identity i2 = IdentityScope.getSystemScope().getIdentity(name);
i2.setPublicKey(pk);
assertTrue(i.identityEquals(i2));
}
示例12: testSetPublicKey2
import java.security.Identity; //导入方法依赖的package包/类
/**
*
* verify Identity.setPublicKey() throws KeyManagementException if key is invalid
*
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "setPublicKey",
args = {java.security.PublicKey.class}
)
public void testSetPublicKey2() throws Exception {
Identity i2 = new IdentityStub("testSetPublicKey2_2", IdentityScope.getSystemScope());
new PublicKeyStub("kkk", "testSetPublicKey2", new byte[]{1,2,3,4,5});
try {
i2.setPublicKey(null);
//fail("KeyManagementException should be thrown - key is null");
} catch (KeyManagementException ok) {}
}
示例13: testGetPublicKey
import java.security.Identity; //导入方法依赖的package包/类
/**
* verify Identity.getPublicKey() returns public key
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getPublicKey",
args = {}
)
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());
}
示例14: test_removeIdentityLjava_security_Identity
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#removeIdentity(java.security.Identity)
*/
public void test_removeIdentityLjava_security_Identity() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
sub.removeIdentity(id);
try {
sub.removeIdentity(id);
fail("KeyManagementException should have been thrown");
} catch (KeyManagementException e) {
// expected
}
}
示例15: test_identities
import java.security.Identity; //导入方法依赖的package包/类
/**
* @tests java.security.IdentityScope#identities()
*/
public void test_identities() throws Exception {
IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
new IdentityScopeSubclass());
Identity id = new IdentitySubclass();
id.setPublicKey(pubKey);
sub.addIdentity(id);
Enumeration en = sub.identities();
assertTrue("Wrong object contained in identities", en.nextElement()
.equals(id));
assertTrue("Contains too many elements", !en.hasMoreElements());
}