Java源码示例:org.bouncycastle.asn1.x500.DirectoryString
示例1
@Override
public void parse(ASN1Primitive derObject) {
ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject);
ASN1Primitive firstObject = derSequence.getObjectAt(0).toASN1Primitive();
this.policyName = new DirectoryString(firstObject.toString());
ASN1Primitive secondObject = derSequence.getObjectAt(1).toASN1Primitive();
String fieldOfApplication = secondObject.toString();
this.fieldOfApplication = new DirectoryString(fieldOfApplication);
this.signingPeriod = new SigningPeriod();
this.signingPeriod.parse(derSequence.getObjectAt(2).toASN1Primitive());
int indice = 3;
ASN1Primitive revocationObject = derSequence.getObjectAt(indice).toASN1Primitive();
if (!(secondObject instanceof DERTaggedObject)) {
indice = 4;
}
if (indice == 3) {
this.revocationDate = new Time();
this.revocationDate.parse(revocationObject);
}
}
示例2
private String getAttributeValueString(ASN1ObjectIdentifier attributeType, ASN1Encodable attributeValue)
throws IOException {
/* AttributeValue ::= ANY */
// Get value string for recognized attribute types
AttributeTypeType attributeTypeType = AttributeTypeType.resolveOid(attributeType.getId());
switch (attributeTypeType) {
case DATE_OF_BIRTH:
return getGeneralizedTimeString(ASN1GeneralizedTime.getInstance(attributeValue));
case SERIAL_NUMBER:
case UNSTRUCTURED_ADDRESS:
case COUNTRY_NAME:
case GENDER:
case COUNTRY_OF_CITIZENSHIP:
case COUNTRY_OF_RESIDENCE:
return DERPrintableString.getInstance(attributeValue).getString();
case COMMON_NAME:
case LOCALITY_NAME:
case STATE_NAME:
case STREET_ADDRESS:
case ORGANIZATION_NAME:
case ORGANIZATIONAL_UNIT:
case TITLE:
case USER_ID:
case PLACE_OF_BIRTH:
return DirectoryString.getInstance(attributeValue).getString();
case MAIL:
case EMAIL_ADDRESS:
case UNSTRUCTURED_NAME:
case DOMAIN_COMPONENT:
return DERIA5String.getInstance(attributeValue).getString();
default:
// Attribute type not recognized - return hex string for value
return HexUtil.getHexString(attributeValue.toASN1Primitive().getEncoded());
}
}
示例3
private String getNamingAuthorityStringValue(NamingAuthority namingAuthority, int indentLevel)
throws IOException {
// @formatter:off
/*
NamingAuthority ::= SEQUENCE
{
namingAuthorityId OBJECT IDENTIFIER OPTIONAL,
namingAuthorityUrl IA5String OPTIONAL,
namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL
}
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
ASN1ObjectIdentifier namingAuthorityId = namingAuthority.getNamingAuthorityId();
String namingAuthorityUrl = namingAuthority.getNamingAuthorityUrl();
DirectoryString namingAuthorityText = namingAuthority.getNamingAuthorityText();
if (namingAuthorityId != null) {
sb.append(INDENT.toString(indentLevel));
sb.append(MessageFormat.format(res.getString("Admission.NamingAuthorityOID"), namingAuthorityId.getId()));
sb.append(NEWLINE);
}
if (namingAuthorityUrl != null) {
sb.append(INDENT.toString(indentLevel));
sb.append(MessageFormat.format(res.getString("Admission.NamingAuthorityURL"), namingAuthorityUrl));
sb.append(NEWLINE);
}
if (namingAuthorityText != null) {
sb.append(INDENT.toString(indentLevel));
sb.append(MessageFormat.format(res.getString("Admission.NamingAuthorityText"),
namingAuthorityText.toString()));
sb.append(NEWLINE);
}
return sb.toString();
}
示例4
private static NamingAuthority buildNamingAuthority(NamingAuthorityType value) {
ASN1ObjectIdentifier oid = (value.getOid() == null) ? null
: new ASN1ObjectIdentifier(value.getOid().getOid());
String url = StringUtil.isBlank(value.getUrl()) ? null : value.getUrl();
DirectoryString text = StringUtil.isBlank(value.getText()) ? null
: new DirectoryString(value.getText());
return new NamingAuthority(oid, url, text);
}
示例5
public DirectoryString getPolicyName() {
return policyName;
}
示例6
public void setPolicyName(DirectoryString policyName) {
this.policyName = policyName;
}
示例7
public DirectoryString getFieldOfApplication() {
return fieldOfApplication;
}
示例8
public void setFieldOfApplication(DirectoryString fieldOfApplication) {
this.fieldOfApplication = fieldOfApplication;
}
示例9
private String getProcurationStringValue(byte[] octets) throws IOException {
// @formatter:off
/*
ProcurationSyntax ::= SEQUENCE
{
country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
typeOfSubstitution [2] EXPLICIT DirectoryString(SIZE(1..128)) OPTIONAL,
signingFor [3] EXPLICIT SigningFor
}
SigningFor ::= CHOICE
{
thirdPerson GeneralName,
certRef IssuerSerial
}
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
ProcurationSyntax procurationSyntax = ProcurationSyntax.getInstance(octets);
String country = procurationSyntax.getCountry();
DirectoryString typeOfSubstitution = procurationSyntax.getTypeOfSubstitution();
GeneralName thirdPerson = procurationSyntax.getThirdPerson();
IssuerSerial certRef = procurationSyntax.getCertRef();
if (country != null) {
sb.append(MessageFormat.format(res.getString("Procuration.Country"), country));
sb.append(NEWLINE);
}
if (typeOfSubstitution != null) {
sb.append(MessageFormat.format(res.getString("Procuration.TypeOfSubstitution"),
typeOfSubstitution.toString()));
sb.append(NEWLINE);
}
if (thirdPerson != null) {
sb.append(MessageFormat.format(res.getString("Procuration.ThirdPerson"),
GeneralNameUtil.toString(thirdPerson)));
sb.append(NEWLINE);
}
if (certRef != null) {
sb.append(res.getString("Procuration.CertRef"));
sb.append(NEWLINE);
sb.append(INDENT);
sb.append(res.getString("Procuration.CertRef.Issuer"));
for (GeneralName generalName : certRef.getIssuer().getNames()) {
sb.append(INDENT);
sb.append(INDENT);
sb.append(GeneralNameUtil.toString(generalName));
sb.append(NEWLINE);
}
sb.append(NEWLINE);
sb.append(INDENT);
sb.append(MessageFormat.format(res.getString("Procuration.CertRef.SN"),
HexUtil.getHexString(certRef.getSerial().getValue())));
sb.append(NEWLINE);
}
return sb.toString();
}
示例10
@Override
public SignatureProductionPlace getSignatureProductionPlace() {
Attribute signatureProductionPlaceAttr = getSignedAttribute(PKCSObjectIdentifiers.id_aa_ets_signerLocation);
if (signatureProductionPlaceAttr == null) {
return null;
}
final ASN1Encodable asn1Encodable = signatureProductionPlaceAttr.getAttrValues().getObjectAt(0);
SignerLocation signerLocation = null;
try {
signerLocation = SignerLocation.getInstance(asn1Encodable);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
if (signerLocation == null) {
return null;
}
final SignatureProductionPlace signatureProductionPlace = new SignatureProductionPlace();
final DirectoryString countryName = signerLocation.getCountry();
if (countryName != null) {
signatureProductionPlace.setCountryName(countryName.getString());
}
final DirectoryString localityName = signerLocation.getLocality();
if (localityName != null) {
signatureProductionPlace.setCity(localityName.getString());
}
final StringBuilder address = new StringBuilder();
final ASN1Sequence seq = signerLocation.getPostalAddress();
if (seq != null) {
for (int ii = 0; ii < seq.size(); ii++) {
if (seq.getObjectAt(ii) instanceof DEROctetString) {
if (address.length() > 0) {
address.append(" / ");
}
// TODO: getOctets returns an array
address.append(new String(((DEROctetString) seq.getObjectAt(ii)).getOctets()));
} else if (seq.getObjectAt(ii) instanceof DERUTF8String) {
if (address.length() > 0) {
address.append(" / ");
}
final DERUTF8String derutf8String = (DERUTF8String) seq.getObjectAt(ii);
address.append(derutf8String.getString());
}
}
}
signatureProductionPlace.setStreetAddress(address.toString());
// This property is not used in CAdES version of signature
// signatureProductionPlace.setStateOrProvince(stateOrProvince);
return signatureProductionPlace;
}
示例11
private String getRestrictionStringValue(byte[] octets) throws IOException {
/* RestrictionSyntax ::= DirectoryString (SIZE(1..1024)) */
return DirectoryString.getInstance(ASN1Primitive.fromByteArray(octets)).toString();
}
示例12
private String getAdditionalInformationStringValue(byte[] octets) throws IOException {
/* AdditionalInformationSyntax ::= DirectoryString (SIZE(1..2048)) */
return DirectoryString.getInstance(ASN1Primitive.fromByteArray(octets)).toString();
}