List of usage examples for org.bouncycastle.asn1 DERIA5String isIA5String
public static boolean isIA5String(String str)
From source file:ca.trustpoint.m2m.EntityNameAttribute.java
License:Apache License
/** * Return true if this instance is a valid EntityName attribute. Values are checked for length and * allowed content against the attribute type rules. * * @return True if this instance is a valid EntityName attribute. *///from ww w . j av a 2s . c om public boolean isValid() { switch (id) { case Country: if ((value == null) || (value.length() != 2)) { return false; } return DERPrintableString.isPrintableString(value); case Organization: case OrganizationalUnit: case Locality: case CommonName: return ((value != null) && (value.length() >= 1) && (value.length() <= 32)); case DistinguishedNameQualifier: case SerialNumber: if ((value == null) || (value.length() < 1) || (value.length() > 32)) { return false; } return DERPrintableString.isPrintableString(value); case StateOrProvince: return ((value != null) && (value.length() >= 1) && (value.length() <= 4)); case DomainComponent: if ((value == null) || (value.length() < 1) || (value.length() > 32)) { return false; } return DERIA5String.isIA5String(value); case RegisteredId: if ((value == null) || (value.length() < 1) || (value.length() > 32)) { return false; } return (ValidationUtils.isValidOid(value)); case OctetsName: if ((value == null) || (value.length() < 1) || (value.length() > 16)) { return false; } return (ValidationUtils.isValidHex(value)); default: return false; } }
From source file:ca.trustpoint.m2m.GeneralName.java
License:Apache License
/** * Validate id and value.//from ww w .j a v a 2 s . co m * * @return true if both are valid, false if either one or both are invalid. */ public boolean isValid() { if (id == null) { return false; } else if (((id == GeneralNameAttributeId.DirectoryName) && (entity == null)) || ((id != GeneralNameAttributeId.DirectoryName) && (value == null))) { return false; } switch (id) { case Rfc822Name: case DnsName: if (!DERIA5String.isIA5String(value)) { return false; } break; case DirectoryName: return entity.isValid(); case Uri: try { new URI(value); } catch (Exception e) { return false; } break; case IpAddress: try { InetAddress.getByName(value); } catch (UnknownHostException e) { return false; } break; case RegisteredId: try { new ASN1ObjectIdentifier(value); } catch (IllegalArgumentException e) { return false; } break; default: return false; } return true; }
From source file:org.opensc.pkcs15.asn1.ref.URL.java
License:Apache License
@Override public DERObject toASN1Object() { if (DERIA5String.isIA5String(this.url)) return new DERIA5String(this.url); return new DERPrintableString(this.url); }
From source file:org.opensc.pkcs15.asn1.ref.URLWithDigest.java
License:Apache License
/** * @param url the url to set//from w w w.j ava2 s .c om */ public void setUrl(String url) { if (!DERIA5String.isIA5String(url)) throw new IllegalArgumentException("url [" + url + "] is not an ASN.1 IA5String."); super.setUrl(url); }