Java 类javax.crypto.ExemptionMechanism 实例源码

项目:In-the-Box-Fork    文件:ExemptionMechanismTest.java   
/**
 * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider)
 * Checks exception order
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getInstance",
    args = {java.lang.String.class, java.lang.String.class}
)
public void testGetInstance() throws Exception {
    //Regression for HARMONY-762
    try {
        ExemptionMechanism.getInstance((String) null, "aaa");
        fail("NoSuchProviderException must be thrown");
    } catch (NoSuchProviderException pe) {
        //expected
    }
    try {
        ExemptionMechanism.getInstance("AlgName", (String)null);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
        //expected
    }
}
项目:In-the-Box-Fork    文件:ExemptionMechanismTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getName",
    args = {}
)
public void test_getName() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    assertEquals(defaultAlg, em.getName());
}
项目:In-the-Box-Fork    文件:ExemptionMechanismTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getProvider",
    args = {}
)
public void test_getProvider() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    assertEquals(mProv, em.getProvider());
}
项目:cn1    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>genExemptionBlob((byte[] output, int outputOffset)</code> method
 */
public void testGenExemptionBlob() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    em.init(key);
    // ExemptionMechanism doesn't check parameters
    // it is a responsibility of ExemptionMechanismSpi
    em.genExemptionBlob(null, 0);
    em.genExemptionBlob(new byte[0], 0);
    em.genExemptionBlob(new byte[10], -5);

}
项目:freeVM    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>genExemptionBlob((byte[] output, int outputOffset)</code> method
 */
public void testGenExemptionBlob() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    em.init(key);
    // ExemptionMechanism doesn't check parameters
    // it is a responsibility of ExemptionMechanismSpi
    em.genExemptionBlob(null, 0);
    em.genExemptionBlob(new byte[0], 0);
    em.genExemptionBlob(new byte[10], -5);

}
项目:freeVM    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>genExemptionBlob((byte[] output, int outputOffset)</code> method
 */
public void testGenExemptionBlob() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    em.init(key);
    // ExemptionMechanism doesn't check parameters
    // it is a responsibility of ExemptionMechanismSpi
    em.genExemptionBlob(null, 0);
    em.genExemptionBlob(new byte[0], 0);
    em.genExemptionBlob(new byte[10], -5);

}
项目:jcommander-addons    文件:ExemptionMechanismConverter.java   
@Override
protected ExemptionMechanism convertImpl(final String value)
        throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException {
    final String[] split = split(value);
    final String algorithm = split[0];
    return isSingle(split) ? ExemptionMechanism.getInstance(value) : ExemptionMechanism.getInstance(algorithm, split[1]);
}
项目:jcommander-addons    文件:ExemptionMechanismConverterTest.java   
@Test
@Ignore
public void testExemptionMechanism() throws NoSuchAlgorithmException, NoSuchPaddingException {
    final String transformation = "KeyEscrow";
    final ExemptionMechanism expected = ExemptionMechanism.getInstance(transformation);
    final ExemptionMechanism actual = convert(transformation);
    Assert.assertEquals(expected.getName(), actual.getName());
    Assert.assertEquals(expected.getProvider(), actual.getProvider());
}
项目:jcommander-addons    文件:ExemptionMechanismConverterTest.java   
@Test
@Ignore
public void testExemptionMechanismWithProvider() throws NoSuchAlgorithmException, NoSuchPaddingException {
    final String transformation = "KeyEscrow";
    final ExemptionMechanism expected = ExemptionMechanism.getInstance(transformation);
    final Provider expectedProvider = expected.getProvider();
    final ExemptionMechanism actual = convert(ProviderUtils.toArguments(transformation, expectedProvider));
    Assert.assertEquals(expected.getName(), actual.getName());
    Assert.assertEquals(expectedProvider, actual.getProvider());
}
项目:In-the-Box-Fork    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>isCryptoAllowed(Key key)</code> method
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "isCryptoAllowed",
    args = {java.security.Key.class}
)
public void testIsCryptoAllowed() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    assertFalse(em.isCryptoAllowed(key));

    em.init(key);
    assertFalse(em.isCryptoAllowed(key));

    em.genExemptionBlob();
    assertTrue(em.isCryptoAllowed(key));

    Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba",
            new byte[] { 1 });
    assertFalse(em.isCryptoAllowed(key1));

    em.init(key1);
    assertFalse(em.isCryptoAllowed(key));
}
项目:In-the-Box-Fork    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>genExemptionBlob((byte[] output, int outputOffset)</code> method
 */
@TestTargetNew(
    level = TestLevel.PARTIAL,
    notes = "Regression test",
    method = "genExemptionBlob",
    args = {byte[].class, int.class}
)
public void testGenExemptionBlob() throws Exception {
    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    em.init(key);
    // ExemptionMechanism doesn't check parameters
    // it is a responsibility of ExemptionMechanismSpi
    em.genExemptionBlob(null, 0);
    em.genExemptionBlob(new byte[0], 0);
    em.genExemptionBlob(new byte[10], -5);
}
项目:In-the-Box-Fork    文件:ExemptionMechanismTest.java   
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        method = "getOutputSize",
        args = {int.class}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        clazz = ExemptionMechanismSpi.class,
        method = "engineGetOutputSize",
        args = {int.class}
    )
})
public void test_getOutputSizeI() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    try {
        em.getOutputSize(10);
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
        //failed
    }

    em.init(key);
    assertEquals(10, em.getOutputSize(10));
}
项目:cn1    文件:ExemptionMechanismTest.java   
/**
 * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider)
 * Checks exception order
 */
public void testGetInstance() throws Exception {
    //Regression for HARMONY-762
    try {
        ExemptionMechanism.getInstance((String) null, "aaa");
        fail("NoSuchProviderException must be thrown");
    } catch (NoSuchProviderException pe) {
        //expected
    }
}
项目:cn1    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>isCryptoAllowed(Key key)</code> method 
 */
public void testIsCryptoAllowed() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    assertFalse(em.isCryptoAllowed(key));

    em.init(key);
    assertFalse(em.isCryptoAllowed(key));

    em.genExemptionBlob();
    assertTrue(em.isCryptoAllowed(key));

    Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba",
            new byte[] { 1 });
    assertFalse(em.isCryptoAllowed(key1));

    em.init(key1);
    assertFalse(em.isCryptoAllowed(key));
}
项目:freeVM    文件:ExemptionMechanismTest.java   
/**
 * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider)
 * Checks exception order
 */
public void testGetInstance() throws Exception {
    //Regression for HARMONY-762
    try {
        ExemptionMechanism.getInstance((String) null, "aaa");
        fail("NoSuchProviderException must be thrown");
    } catch (NoSuchProviderException pe) {
        //expected
    }
}
项目:freeVM    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>isCryptoAllowed(Key key)</code> method 
 */
public void testIsCryptoAllowed() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    assertFalse(em.isCryptoAllowed(key));

    em.init(key);
    assertFalse(em.isCryptoAllowed(key));

    em.genExemptionBlob();
    assertTrue(em.isCryptoAllowed(key));

    Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba",
            new byte[] { 1 });
    assertFalse(em.isCryptoAllowed(key1));

    em.init(key1);
    assertFalse(em.isCryptoAllowed(key));
}
项目:freeVM    文件:ExemptionMechanismTest.java   
/**
 * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider)
 * Checks exception order
 */
public void testGetInstance() throws Exception {
    //Regression for HARMONY-762
    try {
        ExemptionMechanism.getInstance((String) null, "aaa");
        fail("NoSuchProviderException must be thrown");
    } catch (NoSuchProviderException pe) {
        //expected
    }
}
项目:freeVM    文件:ExemptionMechanismTest.java   
/**
 * Test for <code>isCryptoAllowed(Key key)</code> method 
 */
public void testIsCryptoAllowed() throws Exception {

    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
            "Provider for ExemptionMechanism testing",
            srvExemptionMechanism.concat(".").concat(defaultAlg),
            ExemptionMechanismProviderClass);

    ExemptionMechanism em = new ExemptionMechanism(
            new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };

    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);

    assertFalse(em.isCryptoAllowed(key));

    em.init(key);
    assertFalse(em.isCryptoAllowed(key));

    em.genExemptionBlob();
    assertTrue(em.isCryptoAllowed(key));

    Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba",
            new byte[] { 1 });
    assertFalse(em.isCryptoAllowed(key1));

    em.init(key1);
    assertFalse(em.isCryptoAllowed(key));
}
项目:jcommander-addons    文件:ExemptionMechanismConverter.java   
/**
 * Constructs a converter.
 * 
 * @param optionName
 *            The option name, may be null.
 */
public ExemptionMechanismConverter(final String optionName) {
    super(optionName, ExemptionMechanism.class);
}