当前位置: 首页>>代码示例>>Java>>正文


Java PublicKeyStub类代码示例

本文整理汇总了Java中org.apache.harmony.security.tests.support.PublicKeyStub的典型用法代码示例。如果您正苦于以下问题:Java PublicKeyStub类的具体用法?Java PublicKeyStub怎么用?Java PublicKeyStub使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PublicKeyStub类属于org.apache.harmony.security.tests.support包,在下文中一共展示了PublicKeyStub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_toString

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * @tests java.security.Signer#toString()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "toString",
    args = {}
)
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();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:25,代码来源:SignerTest.java

示例2: testGetPrivateKey

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * verify Signer.getPrivateKey() returns null or private key
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getPrivateKey",
    args = {}
)
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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:SignerTest.java

示例3: testAddCertificate1

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的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) {}
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:IdentityTest.java

示例4: testAddCertificate2

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * verify addCertificate(Certificate certificate) adds a certificate for this identity.
 * if the identity does not have a public key, the identity's public key is set to be that specified in the certificate.
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "addCertificate",
    args = {java.security.Certificate.class}
)
public void testAddCertificate2() 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]);
    assertSame(pk1, i.getPublicKey());

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:IdentityTest.java

示例5: testCertificates

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * verify certificates() returns a copy of all certificates for this identity
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "certificates",
    args = {}
)
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]));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:29,代码来源:IdentityTest.java

示例6: testSetPublicKey4

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的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);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:IdentityTest.java

示例7: testGetPrivateKey_denied

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * verify Signer.getPrivateKey() throws SecurityException if permission is denied
 */
public void testGetPrivateKey_denied() throws Exception {
    MySecurityManager sm = new MySecurityManager();
    sm.denied.add(new SecurityPermission("getSignerPrivateKey"));
    System.setSecurityManager(sm);
    try {
        Signer s = new SignerStub("sss6");
        s.setKeyPair(new KeyPair(new PublicKeyStub("public", "fff", null), new PrivateKeyStub("private", "fff", null)));
        try {
            s.getPrivateKey();
            fail("SecurityException should be thrown");
        } catch (SecurityException ok) {}            
    } finally {
        System.setSecurityManager(null);
    }
    
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:SignerTest.java

示例8: testCertificates

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * 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);
    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]));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:23,代码来源:IdentityTest.java

示例9: testIdentityEquals

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * verify Identity.identityEquals(Identity) return true, only if names and public keys are equal 
 */

public void testIdentityEquals() throws Exception {
    String name = "nnn";
    PublicKey pk = new PublicKeyStub("aaa", "fff", new byte[]{1,2,3,4,5});
    Identity 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));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:IdentityTest.java

示例10: testSetPublicKey4

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * 
 * verify Identity.setPublicKey()  removes old key and all identity's certificates
 *
 */
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);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:IdentityTest.java

示例11: testIdentityEquals

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的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));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:32,代码来源:IdentityTest.java

示例12: testSetPublicKey2

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的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) {}
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:IdentityTest.java

示例13: testGetPublicKey

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:IdentityTest.java

示例14: setUp

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
protected void setUp() throws Exception {
    PrivateKeyStub privateKey = new PrivateKeyStub("privateAlgorithm",
            "privateFormat", new byte[] { 0x00, 0x05, 0x10 });
    PublicKeyStub publicKey = new PublicKeyStub("publicAlgorithm",
            "publicFormat", new byte[] { 0x01, 0x02, 0x12 });

    keyPair = new KeyPair(publicKey, privateKey);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:9,代码来源:KeyPairTest.java

示例15: test_toString

import org.apache.harmony.security.tests.support.PublicKeyStub; //导入依赖的package包/类
/**
 * @tests 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();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:SignerTest.java


注:本文中的org.apache.harmony.security.tests.support.PublicKeyStub类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。