Search in sources :

Example 76 with Provider

use of java.security.Provider in project robovm by robovm.

the class ProviderServiceTest method testGetClassName.

public void testGetClassName() {
    Provider p = new MyProvider();
    Provider.Service s1 = new Provider.Service(p, "type", "algorithm", "className", null, null);
    assertTrue(s1.getClassName().equals("className"));
    Provider.Service s2 = new Provider.Service(p, "SecureRandom", "algorithm", "tests.java.security.support.RandomImpl", null, null);
    assertTrue(s2.getClassName().equals("tests.java.security.support.RandomImpl"));
}
Also used : Service(java.security.Provider.Service) Service(java.security.Provider.Service) Provider(java.security.Provider)

Example 77 with Provider

use of java.security.Provider in project robovm by robovm.

the class ProviderServiceTest method testGetAttribute.

public void testGetAttribute() {
    Provider p = new MyProvider();
    Provider.Service s = new Provider.Service(p, "type", "algorithm", "className", null, null);
    try {
        s.getAttribute(null);
        fail("No expected NullPointerException");
    } catch (NullPointerException e) {
    }
    if (s.getAttribute("aaa") != null) {
        fail("getAttribute(aaa) failed");
    }
    HashMap<String, String> hm = new HashMap<String, String>();
    hm.put("attribute", "value");
    hm.put("KeySize", "1024");
    hm.put("AAA", "BBB");
    s = new Provider.Service(p, "type", "algorithm", "className", null, hm);
    if (s.getAttribute("bbb") != null) {
        fail("getAttribute(bbb) failed");
    }
    if (!s.getAttribute("attribute").equals("value")) {
        fail("getAttribute(attribute) failed");
    }
    if (!s.getAttribute("KeySize").equals("1024")) {
        fail("getAttribute(KeySize) failed");
    }
}
Also used : HashMap(java.util.HashMap) Service(java.security.Provider.Service) Service(java.security.Provider.Service) Provider(java.security.Provider)

Example 78 with Provider

use of java.security.Provider in project robovm by robovm.

the class ProviderServiceTest method testGetType.

public void testGetType() {
    Provider p = new MyProvider();
    Provider.Service s1 = new Provider.Service(p, "type", "algorithm", "className", null, null);
    assertTrue(s1.getType().equals("type"));
    Provider.Service s2 = new Provider.Service(p, "SecureRandom", "algorithm", "tests.java.security.support.RandomImpl", null, null);
    assertTrue(s2.getType().equals("SecureRandom"));
}
Also used : Service(java.security.Provider.Service) Service(java.security.Provider.Service) Provider(java.security.Provider)

Example 79 with Provider

use of java.security.Provider in project robovm by robovm.

the class CertificateFactory2Test method GetInstance03.

/**
     * Test for <code>getInstance(String type, Provider provider)</code>
     * method
     * Assertions:
     * throws NullPointerException when type is null
     * throws CertificateException when type is not available
     * throws IllegalArgumentException when provider is null;
     * returns CertificateFactory object
     */
public void GetInstance03(boolean mode) throws CertificateException, IllegalArgumentException, CRLException {
    try {
        CertificateFactory.getInstance(null, mProv);
        fail("NullPointerException or CertificateException must be thrown when type is null");
    } catch (CertificateException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            CertificateFactory.getInstance(invalidValues[i], mProv);
            fail("CertificateException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
        } catch (CertificateException e) {
        }
    }
    Provider prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertificateFactory.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    CertificateFactory cerF;
    for (int i = 0; i < validValues.length; i++) {
        cerF = CertificateFactory.getInstance(validValues[i], mProv);
        assertEquals("Incorrect type", cerF.getType(), validValues[i]);
        assertEquals("Incorrect provider", cerF.getProvider(), mProv);
        checkResult(cerF, mode);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) Provider(java.security.Provider)

Example 80 with Provider

use of java.security.Provider in project robovm by robovm.

the class CertificateFactory4Test method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * java.security.cert.CertificateFactory#getInstance(java.lang.String,
     *        java.lang.String)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
    // Test for method java.security.cert.CertificateFactory
    // java.security.cert.CertificateFactory.getInstance(java.lang.String,
    // java.lang.String)
    Provider[] providers = Security.getProviders("CertificateFactory.X.509");
    if (providers != null) {
        for (int i = 0; i < providers.length; i++) {
            CertificateFactory fact = CertificateFactory.getInstance("X.509", providers[i].getName());
            assertNotNull("factory is null", fact);
        }
    // end for
    } else {
        fail("No providers support CertificateFactory.X.509");
    }
    // exception case
    try {
        CertificateFactory.getInstance("X.509", "IHaventBeenConfigured");
        fail("Should have thrown NoSuchProviderException");
    } catch (NoSuchProviderException e) {
    // Expected
    }
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory) Provider(java.security.Provider)

Aggregations

Provider (java.security.Provider)243 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)26 MessageDigest (java.security.MessageDigest)21 List (java.util.List)20 Key (java.security.Key)19 KeyStore (java.security.KeyStore)19 Service (java.security.Provider.Service)15 ExemptionMechanism (javax.crypto.ExemptionMechanism)14 SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)14 InvalidKeyException (java.security.InvalidKeyException)13 SecureRandom (java.security.SecureRandom)13 IOException (java.io.IOException)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 CertificateException (java.security.cert.CertificateException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11