use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jaxdb by jaxdb.
the class SQLiteDecompiler method makeColumn.
@Override
$Column makeColumn(final String columnName, final String typeName, final long size, final int decimalDigits, final String _default, final Boolean nullable, final Boolean autoIncrement) {
final $Column column;
if (typeName.startsWith("BIGINT")) {
final $Bigint type = newColumn($Bigint.class);
if (size != 2000000000)
type.setPrecision$(new $Bigint.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Bigint.Default$(Long.valueOf(_default)));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Bigint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if (typeName.startsWith("BINARY")) {
final $Binary type = newColumn($Binary.class);
final Long length = getLength(typeName);
if (length != null)
type.setLength$(new $Binary.Length$(length));
column = type;
} else if (typeName.startsWith("BLOB")) {
final $Blob type = newColumn($Blob.class);
final Long length = getLength(typeName);
if (length != null)
type.setLength$(new $Blob.Length$(length));
column = type;
} else if ("BOOLEAN".equals(typeName)) {
final $Boolean type = newColumn($Boolean.class);
if (_default != null)
type.setDefault$(new $Boolean.Default$(Boolean.parseBoolean(_default)));
column = type;
} else if (typeName.startsWith("VARCHAR") || typeName.startsWith("CHARACTER")) {
final $Char type = newColumn($Char.class);
if (typeName.startsWith("VARCHAR"))
type.setVarying$(new $Char.Varying$(true));
final Long length = getLength(typeName);
if (length != null)
type.setLength$(new $Char.Length$(length));
if (_default != null)
type.setDefault$(new $Char.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if (typeName.startsWith("TEXT")) {
final $Clob type = newColumn($Clob.class);
final Long length = getLength(typeName);
if (length != null)
type.setLength$(new $Clob.Length$(length));
column = type;
} else if ("DATE".equals(typeName)) {
final $Date type = newColumn($Date.class);
if (_default != null)
type.setDefault$(new $Date.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("DATETIME".equals(typeName)) {
final $Datetime type = newColumn($Datetime.class);
if (size != 2000000000)
type.setPrecision$(new $Datetime.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Datetime.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if (typeName.startsWith("DECIMAL")) {
final $Decimal type = newColumn($Decimal.class);
if (!"DECIMAL(15,0)".equals(typeName)) {
final int open = typeName.indexOf('(');
if (open > 0) {
final int comma = typeName.indexOf(',', open + 1);
if (comma > open) {
final int close = typeName.indexOf(')', comma + 1);
if (close > comma) {
type.setPrecision$(new $Decimal.Precision$(Integer.valueOf(typeName.substring(open + 1, comma).trim())));
type.setScale$(new $Decimal.Scale$(Integer.valueOf(typeName.substring(comma + 1, close).trim())));
}
}
}
}
if (_default != null)
type.setDefault$(new $Decimal.Default$(new BigDecimal(_default)));
column = type;
} else if ("DOUBLE".equals(typeName)) {
final $Double type = newColumn($Double.class);
if (_default != null)
type.setDefault$(new $Double.Default$(Double.valueOf(_default)));
column = type;
} else // }
if ("FLOAT".equals(typeName)) {
final $Float type = newColumn($Float.class);
if (_default != null)
type.setDefault$(new $Float.Default$(Float.valueOf(_default)));
column = type;
} else if (typeName.startsWith("INT") || typeName.startsWith("MEDIUMINT")) {
final $Int type = newColumn($Int.class);
if (size != 2000000000)
type.setPrecision$(new $Int.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Int.Default$(Integer.valueOf(_default)));
if ("INTEGER".equals(typeName))
type.setGenerateOnInsert$(new $Int.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("SMALLINT".equals(typeName)) {
final $Smallint type = newColumn($Smallint.class);
if (size != 2000000000)
type.setPrecision$(new $Smallint.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Smallint.Default$(Short.valueOf(_default)));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Smallint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("TIME".equals(typeName)) {
final $Time type = newColumn($Time.class);
if (size != 2000000000)
type.setPrecision$(new $Time.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Time.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("TINYINT".equals(typeName)) {
final $Tinyint type = newColumn($Tinyint.class);
if (size != 2000000000)
type.setPrecision$(new $Tinyint.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Tinyint.Default$(Byte.valueOf(_default)));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Tinyint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else {
throw new UnsupportedOperationException("Unsupported column type: " + typeName);
}
column.setName$(new $Column.Name$(columnName));
if (nullable != null && !nullable)
column.setNull$(new $Column.Null$(false));
return column;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class CMCStatusInfo method addBodyPartID.
/**
* Adds a BodyPartID to the bodyList SEQUENCE.
*/
public void addBodyPartID(int id) {
INTEGER id1 = new INTEGER(id);
assert (id1.compareTo(BODYIDMAX) <= 0);
bodyList.addElement(id1);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class PKIPublicationInfo method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(new INTEGER(action));
seq.addElement(pubInfos);
seq.encode(implicitTag, ostream);
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class EncryptedPrivateKeyInfo method createPBES2.
/**
* Export a private key in PBES2 format, using a random PBKDF2 salt.
*
* Token must support the CKM_PKCS5_PBKD2 mechanism.
*
* @param saltLen Length of salt in bytes (default: 16)
* @param kdfIterations PBKDF2 iterations (default: 2000)
* @param encAlg The symmetric encryption algorithm for enciphering the
* private key. Determines the size of derived key.
* @param pwd Password
* @param charToByteConverter The mechanism for converting the characters
* in the password into bytes. If null, the default mechanism
* will be used, which is UTF8.
* @param privateKeyInfo The encoded PrivateKeyInfo to be encrypted and
* stored in the EncryptedContentInfo.
*/
public static EncryptedPrivateKeyInfo createPBES2(int saltLen, int kdfIterations, EncryptionAlgorithm encAlg, Password pwd, KeyGenerator.CharToByteConverter charToByteConverter, PrivateKeyInfo privateKeyInfo) throws NotInitializedException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, TokenException, CharConversionException {
if (encAlg == null)
throw new IllegalArgumentException("encAlg cannot be null");
if (pwd == null)
throw new IllegalArgumentException("pwd cannot be null");
if (privateKeyInfo == null)
throw new IllegalArgumentException("privateKeyInfo cannot be null");
if (kdfIterations < 1)
kdfIterations = 2000;
if (saltLen < 1)
saltLen = 16;
try {
// generate random PBKDF2 salt
SecureRandom random = new SecureRandom();
byte[] salt = new byte[saltLen];
random.nextBytes(salt);
// derive symmetric key from passphrase using PBKDF2
CryptoManager cm = CryptoManager.getInstance();
CryptoToken token = cm.getInternalCryptoToken();
KeyGenerator kg = token.getKeyGenerator(PBEAlgorithm.PBE_PKCS5_PBKDF2);
PBEKeyGenParams pbekgParams = new PBEKeyGenParams(pwd.getChars(), salt, kdfIterations, encAlg);
if (charToByteConverter != null)
kg.setCharToByteConverter(charToByteConverter);
kg.initialize(pbekgParams);
SymmetricKey sk = kg.generate();
// encrypt PrivateKeyInfo
byte[] iv = new byte[encAlg.getBlockSize()];
random.nextBytes(iv);
Cipher cipher = token.getCipherContext(encAlg);
cipher.initEncrypt(sk, new IVParameterSpec(iv));
byte[] encData = cipher.doFinal(ASN1Util.encode(privateKeyInfo));
// construct KDF AlgorithmIdentifier
SEQUENCE paramsKdf = new SEQUENCE();
paramsKdf.addElement(new OCTET_STRING(salt));
paramsKdf.addElement(new INTEGER(kdfIterations));
paramsKdf.addElement(new INTEGER(sk.getLength()));
AlgorithmIdentifier algIdKdf = new AlgorithmIdentifier(PBEAlgorithm.PBE_PKCS5_PBKDF2.toOID(), paramsKdf);
// construct encryption AlgorithmIdentifier
AlgorithmIdentifier algIdEnc = new AlgorithmIdentifier(encAlg.toOID(), new OCTET_STRING(iv));
// construct "composite" PBES2 AlgorithmIdentifier
SEQUENCE paramsPBES2 = new SEQUENCE();
paramsPBES2.addElement(algIdKdf);
paramsPBES2.addElement(algIdEnc);
AlgorithmIdentifier algIdPBES2 = new AlgorithmIdentifier(PBEAlgorithm.PBE_PKCS5_PBES2.toOID(), paramsPBES2);
// construct EncryptedPrivateKeyInfo
return new EncryptedPrivateKeyInfo(algIdPBES2, new OCTET_STRING(encData));
} catch (IllegalBlockSizeException e) {
throw new RuntimeException("IllegalBlockSizeException in EncryptedContentInfo.createPBES2: " + e.getMessage(), e);
} catch (BadPaddingException e) {
throw new RuntimeException("BadPaddingException in EncryptedContentInfo.createPBES2: " + e.getMessage(), e);
}
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.
the class KeyFactorySpi1_2 method engineGeneratePrivate.
/**
* We don't support RSAPrivateKeySpec because it doesn't have enough
* information. You need to provide an RSAPrivateCrtKeySpec.
*/
@Override
protected java.security.PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
try {
if (keySpec instanceof RSAPrivateCrtKeySpec) {
//
// PKCS #1 RSAPrivateKey
//
RSAPrivateCrtKeySpec spec = (RSAPrivateCrtKeySpec) keySpec;
SEQUENCE privKey = new SEQUENCE();
// version
privKey.addElement(new INTEGER(0));
privKey.addElement(new INTEGER(spec.getModulus()));
privKey.addElement(new INTEGER(spec.getPublicExponent()));
privKey.addElement(new INTEGER(spec.getPrivateExponent()));
privKey.addElement(new INTEGER(spec.getPrimeP()));
privKey.addElement(new INTEGER(spec.getPrimeQ()));
privKey.addElement(new INTEGER(spec.getPrimeExponentP()));
privKey.addElement(new INTEGER(spec.getPrimeExponentQ()));
privKey.addElement(new INTEGER(spec.getCrtCoefficient()));
AlgorithmIdentifier algID = new AlgorithmIdentifier(PrivateKey.RSA.toOID(), null);
OCTET_STRING encodedPrivKey = new OCTET_STRING(ASN1Util.encode(privKey));
PrivateKeyInfo pki = new PrivateKeyInfo(// version
new INTEGER(0), algID, encodedPrivKey, // OPTIONAL SET OF Attribute
(SET) null);
return PK11PrivKey.fromPrivateKeyInfo(ASN1Util.encode(pki), TokenSupplierManager.getTokenSupplier().getThreadToken());
} else if (keySpec instanceof DSAPrivateKeySpec) {
DSAPrivateKeySpec spec = (DSAPrivateKeySpec) keySpec;
SEQUENCE pqgParams = new SEQUENCE();
pqgParams.addElement(new INTEGER(spec.getP()));
pqgParams.addElement(new INTEGER(spec.getQ()));
pqgParams.addElement(new INTEGER(spec.getG()));
AlgorithmIdentifier algID = new AlgorithmIdentifier(PrivateKey.DSA.toOID(), pqgParams);
OCTET_STRING privateKey = new OCTET_STRING(ASN1Util.encode(new INTEGER(spec.getX())));
PrivateKeyInfo pki = new PrivateKeyInfo(// version
new INTEGER(0), algID, privateKey, // OPTIONAL SET OF Attribute
null);
// Derive the public key from the private key
BigInteger y = spec.getG().modPow(spec.getX(), spec.getP());
byte[] yBA = y.toByteArray();
// we need to chop off a leading zero byte
if (y.bitLength() % 8 == 0) {
byte[] newBA = new byte[yBA.length - 1];
assert (newBA.length >= 0);
System.arraycopy(yBA, 1, newBA, 0, newBA.length);
yBA = newBA;
}
return PK11PrivKey.fromPrivateKeyInfo(ASN1Util.encode(pki), TokenSupplierManager.getTokenSupplier().getThreadToken(), yBA);
} else if (keySpec instanceof PKCS8EncodedKeySpec) {
return PK11PrivKey.fromPrivateKeyInfo((PKCS8EncodedKeySpec) keySpec, TokenSupplierManager.getTokenSupplier().getThreadToken());
}
throw new InvalidKeySpecException("Unsupported KeySpec type: " + keySpec.getClass().getName());
} catch (TokenException te) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
te.printStackTrace(pw);
throw new InvalidKeySpecException("TokenException: " + sw.toString());
}
}
Aggregations