Code example for ExemptionMechanism

Methods: genExemptionBlobgetOutputSizeinit, ExemptionMechanism.init

0
        Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
        byte[] emptyA = new byte[0];
        int len = MyExemptionMechanismSpi.getLength();
        byte[] byteA = new byte[len];
        try { 
            exMech.genExemptionBlob();
            fail("IllegalStateException must be thrown");
        } catch (IllegalStateException e) {
        } 
        try { 
            exMech.genExemptionBlob(byteA);
            fail("IllegalStateException must be thrown");
        } catch (IllegalStateException e) {
        } 
        try { 
            exMech.genExemptionBlob(byteA, 1);
            fail("IllegalStateException must be thrown");
        } catch (IllegalStateException e) {
        } 
        try { 
            exMech.getOutputSize(0);
            fail("IllegalStateException must be thrown");
        } catch (IllegalStateException e) {
        } 
 
        exMech.init(key);
        byte[] bbRes = exMech.genExemptionBlob();
        assertEquals("Incorrect length", bbRes.length, len);
        assertEquals("Incorrect result", exMech.genExemptionBlob(new byte[5]), 5);
        assertEquals("Incorrect result", exMech.genExemptionBlob(bbRes), len);
 
        AlgorithmParameters params = null;
        exMech.init(key, params);
        AlgorithmParameterSpec parSpec = null;
        exMech.init(key, parSpec);
        key = new SecretKeySpec(new byte[10], "DSA");
        try { 
            exMech.init(key);
            fail("ExemptionMechanismException must be thrown");
        } catch (ExemptionMechanismException e) {
            assertTrue("Empty message", (e.getMessage().length() > 0));
        } 
        try { 
            exMech.init(key, params);
            fail("ExemptionMechanismException must be thrown");
        } catch (ExemptionMechanismException e) {
            assertTrue("Empty message", (e.getMessage().length() > 0));
        } 
        try { 
            exMech.init(key, parSpec);
            fail("ExemptionMechanismException must be thrown");
        } catch (ExemptionMechanismException e) {
            assertTrue("Empty message", (e.getMessage().length() > 0));
        } 
    } 
Experience pair programming with AI  Get Codota for Java