use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.
the class AttributeTable method getAll.
/**
* Return all the attributes matching the OBJECT IDENTIFIER oid. The vector will be
* empty if there are no attributes of the required type present.
*
* @param oid type of attribute required.
* @return a vector of all the attributes found of type oid.
*/
public ASN1EncodableVector getAll(ASN1ObjectIdentifier oid) {
ASN1EncodableVector v = new ASN1EncodableVector();
Object value = attributes.get(oid);
if (value instanceof Vector) {
Enumeration e = ((Vector) value).elements();
while (e.hasMoreElements()) {
v.add((Attribute) e.nextElement());
}
} else if (value != null) {
v.add((Attribute) value);
}
return v;
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.
the class SignedData method calculateVersion.
// RFC3852, section 5.1:
// IF ((certificates is present) AND
// (any certificates with a type of other are present)) OR
// ((crls is present) AND
// (any crls with a type of other are present))
// THEN version MUST be 5
// ELSE
// IF (certificates is present) AND
// (any version 2 attribute certificates are present)
// THEN version MUST be 4
// ELSE
// IF ((certificates is present) AND
// (any version 1 attribute certificates are present)) OR
// (any SignerInfo structures are version 3) OR
// (encapContentInfo eContentType is other than id-data)
// THEN version MUST be 3
// ELSE version MUST be 1
//
private ASN1Integer calculateVersion(ASN1ObjectIdentifier contentOid, ASN1Set certs, ASN1Set crls, ASN1Set signerInfs) {
boolean otherCert = false;
boolean otherCrl = false;
boolean attrCertV1Found = false;
boolean attrCertV2Found = false;
if (certs != null) {
for (Enumeration en = certs.getObjects(); en.hasMoreElements(); ) {
Object obj = en.nextElement();
if (obj instanceof ASN1TaggedObject) {
ASN1TaggedObject tagged = ASN1TaggedObject.getInstance(obj);
if (tagged.getTagNo() == 1) {
attrCertV1Found = true;
} else if (tagged.getTagNo() == 2) {
attrCertV2Found = true;
} else if (tagged.getTagNo() == 3) {
otherCert = true;
}
}
}
}
if (otherCert) {
return new ASN1Integer(5);
}
if (// no need to check if otherCert is true
crls != null) {
for (Enumeration en = crls.getObjects(); en.hasMoreElements(); ) {
Object obj = en.nextElement();
if (obj instanceof ASN1TaggedObject) {
otherCrl = true;
}
}
}
if (otherCrl) {
return VERSION_5;
}
if (attrCertV2Found) {
return VERSION_4;
}
if (attrCertV1Found) {
return VERSION_3;
}
if (checkForVersion3(signerInfs)) {
return VERSION_3;
}
if (!CMSObjectIdentifiers.data.equals(contentOid)) {
return VERSION_3;
}
return VERSION_1;
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.
the class X509Name method decodeOID.
private ASN1ObjectIdentifier decodeOID(String name, Hashtable lookUp) {
name = name.trim();
if (Strings.toUpperCase(name).startsWith("OID.")) {
return new ASN1ObjectIdentifier(name.substring(4));
} else if (name.charAt(0) >= '0' && name.charAt(0) <= '9') {
return new ASN1ObjectIdentifier(name);
}
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) lookUp.get(Strings.toLowerCase(name));
if (oid == null) {
throw new IllegalArgumentException("Unknown object id - " + name + " - passed to distinguished name");
}
return oid;
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.
the class X509Name method toString.
/**
* convert the structure to a string - if reverse is true the
* oids and values are listed out starting with the last element
* in the sequence (ala RFC 2253), otherwise the string will begin
* with the first element of the structure. If no string definition
* for the oid is found in oidSymbols the string value of the oid is
* added. Two standard symbol tables are provided DefaultSymbols, and
* RFC2253Symbols as part of this class.
*
* @param reverse if true start at the end of the sequence and work back.
* @param oidSymbols look up table strings for oids.
*/
public String toString(boolean reverse, Hashtable oidSymbols) {
StringBuffer buf = new StringBuffer();
Vector components = new Vector();
boolean first = true;
StringBuffer ava = null;
for (int i = 0; i < ordering.size(); i++) {
if (((Boolean) added.elementAt(i)).booleanValue()) {
ava.append('+');
appendValue(ava, oidSymbols, (ASN1ObjectIdentifier) ordering.elementAt(i), (String) values.elementAt(i));
} else {
ava = new StringBuffer();
appendValue(ava, oidSymbols, (ASN1ObjectIdentifier) ordering.elementAt(i), (String) values.elementAt(i));
components.addElement(ava);
}
}
if (reverse) {
for (int i = components.size() - 1; i >= 0; i--) {
if (first) {
first = false;
} else {
buf.append(',');
}
buf.append(components.elementAt(i).toString());
}
} else {
for (int i = 0; i < components.size(); i++) {
if (first) {
first = false;
} else {
buf.append(',');
}
buf.append(components.elementAt(i).toString());
}
}
return buf.toString();
}
use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.
the class X509Name method toASN1Primitive.
public ASN1Primitive toASN1Primitive() {
if (seq == null) {
ASN1EncodableVector vec = new ASN1EncodableVector();
ASN1EncodableVector sVec = new ASN1EncodableVector();
ASN1ObjectIdentifier lstOid = null;
for (int i = 0; i != ordering.size(); i++) {
ASN1EncodableVector v = new ASN1EncodableVector();
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ordering.elementAt(i);
v.add(oid);
String str = (String) values.elementAt(i);
v.add(converter.getConvertedValue(oid, str));
if (lstOid == null || ((Boolean) this.added.elementAt(i)).booleanValue()) {
sVec.add(new DERSequence(v));
} else {
vec.add(new DERSet(sVec));
sVec = new ASN1EncodableVector();
sVec.add(new DERSequence(v));
}
lstOid = oid;
}
vec.add(new DERSet(sVec));
seq = new DERSequence(vec);
}
return seq;
}
Aggregations