use of java.security.Provider in project robovm by robovm.
the class ExemptionMechanismTest method test_getName.
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());
}
use of java.security.Provider in project robovm by robovm.
the class KeyAgreementTest method testGetInstanceStringProvider02.
/**
* Test for <code> getInstance(String algorithm, Provider provider)</code>
* method Assertions: throws IllegalArgumentException when provider is null
*/
public void testGetInstanceStringProvider02() throws NoSuchAlgorithmException, IllegalArgumentException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
Provider provider = null;
for (int i = 0; i < invalidValues.length; i++) {
try {
KeyAgreement.getInstance(invalidValues[i], provider);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
}
}
use of java.security.Provider in project robovm by robovm.
the class myMac method testMac06.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code> method
* Assertion: throws IllegalArgumentException when provider is null
*/
public void testMac06() throws NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
Provider provider = null;
for (int i = 0; i < validValues.length; i++) {
try {
Mac.getInstance(validValues[i], provider);
fail("IllegalArgumentException must be thrown when provider is null");
} catch (IllegalArgumentException e) {
}
}
}
use of java.security.Provider in project robovm by robovm.
the class Cipher method getCipher.
/**
* Find appropriate Cipher according the specification rules
*
* @param transformation
* @param provider
* @return
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
*/
private static synchronized Cipher getCipher(String transformation, Provider provider) throws NoSuchAlgorithmException, NoSuchPaddingException {
if (transformation == null || transformation.isEmpty()) {
throw invalidTransformation(transformation);
}
String[] transf = checkTransformation(transformation);
boolean needSetPadding = false;
boolean needSetMode = false;
Object engineSpi = null;
Provider engineProvider = provider;
if (transf[1] == null && transf[2] == null) {
// "algorithm"
if (provider == null) {
Engine.SpiAndProvider sap = ENGINE.getInstance(transf[0], null);
engineSpi = sap.spi;
engineProvider = sap.provider;
} else {
engineSpi = ENGINE.getInstance(transf[0], provider, null);
}
} else {
String[] searchOrder = { // "algorithm/mode/padding"
transf[0] + "/" + transf[1] + "/" + transf[2], // "algorithm/mode"
transf[0] + "/" + transf[1], // "algorithm//padding"
transf[0] + "//" + transf[2], // "algorithm"
transf[0] };
int i;
for (i = 0; i < searchOrder.length; i++) {
try {
if (provider == null) {
Engine.SpiAndProvider sap = ENGINE.getInstance(searchOrder[i], null);
engineSpi = sap.spi;
engineProvider = sap.provider;
} else {
engineSpi = ENGINE.getInstance(searchOrder[i], provider, null);
}
break;
} catch (NoSuchAlgorithmException e) {
if (i == searchOrder.length - 1) {
throw new NoSuchAlgorithmException(transformation, e);
}
}
}
switch(i) {
case // "algorithm/mode"
1:
needSetPadding = true;
break;
case // "algorithm//padding"
2:
needSetMode = true;
break;
case // "algorithm"
3:
needSetPadding = true;
needSetMode = true;
}
}
if (engineSpi == null || engineProvider == null) {
throw new NoSuchAlgorithmException(transformation);
}
if (!(engineSpi instanceof CipherSpi)) {
throw new NoSuchAlgorithmException(engineSpi.getClass().getName());
}
CipherSpi cspi = (CipherSpi) engineSpi;
Cipher c = new Cipher(cspi, engineProvider, transformation);
if (needSetMode) {
c.spiImpl.engineSetMode(transf[1]);
}
if (needSetPadding) {
c.spiImpl.engineSetPadding(transf[2]);
}
return c;
}
use of java.security.Provider in project robovm by robovm.
the class SignatureTest method getTestSignature.
private Signature getTestSignature() throws NoSuchAlgorithmException {
Provider provider = new MyProvider("TestProvider", 1.0, "Test Provider", "Signature.ABC", MySignature.class.getName());
Security.insertProviderAt(provider, 1);
try {
return Signature.getInstance("ABC");
} finally {
Security.removeProvider("TestProvider");
}
}
Aggregations