com.dyadicsec.provider.KeyParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.dyadicsec.provider;
import com.dyadicsec.pkcs11.Policy;
/**
* Created by valery.osheter on 15-Mar-17.
*/
public class KeyParameters
{
public static final int EXPORT_NONE = 3;
public static final int EXPORT_WRAP_WITH_TRUSTED = 2;
public static final int EXPORT_WRAP = 1;
public static final int EXPORT_PLAIN = 0;
int exportLevelMode = -1;
int signMode = -1;
int verifyMode = -1;
int encryptMode = -1;
int decryptMode = -1;
int wrapMode = -1;
int unwrapMode = -1;
int deriveMode = -1;
int trustedMode = -1;
int hwMode = -1;
private boolean allowEncrypt = true;
private boolean allowDecrypt = true;
private boolean allowSign = true;
private boolean allowVerify = true;
private boolean allowDerive = true;
private boolean extractable = false;
private boolean sensitive = true;
private boolean trusted = false;
private boolean token = true;
public boolean isSetSign() { return signMode >=0; }
public boolean isSetVerify() { return verifyMode >=0; }
public boolean isSetEncrypt() { return encryptMode >=0; }
public boolean isSetDecrypt() { return decryptMode >=0; }
public boolean isSetWrap() { return wrapMode >=0; }
public boolean isSetUnwrap() { return unwrapMode >=0; }
public boolean isSetDerive() { return deriveMode >=0; }
public boolean isSetTrusted() { return trustedMode >=0; }
public boolean isSetToken() { return hwMode >=0; }
public boolean isSetExportProtection() { return exportLevelMode >=0; }
public void setToken(boolean v)
{
token = v;
hwMode = v ? 1 : 0;
}
public void setAllowEncrypt(boolean v)
{
allowEncrypt = v;
encryptMode = v ? 1 : 0;
}
public void setAllowDecrypt(boolean v)
{
allowDecrypt = v;
decryptMode = v ? 1 : 0;
}
public void setAllowSign(boolean v)
{
allowSign = v;
signMode = v ? 1 : 0;
}
public void setAllowVerify(boolean v)
{
allowVerify = v;
verifyMode = v ? 1 : 0;
}
public void setAllowDerive(boolean v)
{
allowDerive = v;
deriveMode = v ? 1 : 0;
}
public void setTrusted(boolean v)
{
trusted = v;
trustedMode = v ? 1 : 0;
}
public void setWrap(boolean v)
{
wrapMode = v ? 1 : 0;
}
public void setUnwrap(boolean v)
{
unwrapMode = v ? 1 : 0;
}
public void setExportProtection(int exportLevel)
{
if (exportLevelEXPORT_NONE) throw new IllegalArgumentException("Invalid export level");
this.exportLevelMode = exportLevel;
}
public int getExportProtection()
{
return exportLevelMode <0 ? EXPORT_NONE : exportLevelMode;
}
public void setExtractable(boolean v) { extractable = v; }
public void setSensitive(boolean v)
{
sensitive = v;
}
public boolean isAllowEncrypt()
{
return allowEncrypt;
}
public boolean isAllowDecrypt()
{
return allowDecrypt;
}
public boolean isAllowSign()
{
return allowSign;
}
public boolean isAllowVerify()
{
return allowVerify;
}
public boolean isAllowDerive()
{
return allowDerive;
}
public boolean isTrusted()
{
return trusted;
}
public boolean isExtractable()
{
return extractable;
}
public boolean isSensitive()
{
return sensitive;
}
public boolean isAllowWrap()
{
return wrapMode!=0;
}
public boolean isAllowUnwrap()
{
return unwrapMode!=0;
}
static Policy toPolicy(KeyParameters params)
{
if (params == null) return null;
Policy policy = new Policy();
policy.setToken(params == null || params.token);
policy.setEncrypt(params == null || params.allowEncrypt);
policy.setDecrypt(params == null || params.allowDecrypt);
policy.setSign(params == null || params.allowSign);
policy.setVerify(params == null || params.allowVerify);
policy.setDerive(params == null || params.allowDerive);
policy.setExtractable(params != null && params.extractable);
policy.setSensitive(params == null || params.sensitive);
policy.setTrusted(params != null && params.trusted);
return policy;
}
}