Example usage for org.bouncycastle.asn1.smime SMIMECapabilities getCapabilities

List of usage examples for org.bouncycastle.asn1.smime SMIMECapabilities getCapabilities

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.smime SMIMECapabilities getCapabilities.

Prototype

public Vector getCapabilities(ASN1ObjectIdentifier capability) 

Source Link

Document

returns a vector with 0 or more objects of all the capabilities matching the passed in capability OID.

Usage

From source file:com.jlocksmith.util.ExtensionUtil.java

License:Open Source License

/**
 * Get SMIME Capabilities String Value/* w  w w  .j  a va  2 s .  co m*/
 * 
 * @param bytes
 * 
 * @return String
 * 
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private String getSmimeCapabilitiesStringValue(byte[] bytes) throws IOException {
    SMIMECapabilities caps = SMIMECapabilities.getInstance(toDERObject(bytes));

    String sParams = localeUtil.getString("SmimeParameters");

    StringBuffer sb = new StringBuffer();

    for (Iterator<SMIMECapability> i = caps.getCapabilities(null).iterator(); i.hasNext();) {
        SMIMECapability cap = (SMIMECapability) i.next();

        String sCapId = cap.getCapabilityID().getId();
        String sCap = getResource(sCapId, "UnrecognisedSmimeCapability");

        sb.append(MessageFormat.format(sCap, new Object[] { sCapId }));

        DEREncodable params;

        if ((params = cap.getParameters()) != null) {
            sb.append("\n\t");
            sb.append(MessageFormat.format(sParams, new Object[] { getObjectString(params) }));
        }

        sb.append('\n');
    }

    return sb.toString();
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get S/MIME capabilities (1.2.840.113549.1.9.15) extension value as a string.
 * /*from w w w . j a v  a  2  s.  c o  m*/
 * <pre>
 * SMIMECapability ::= SEQUENCE {
 *   capabilityID OBJECT IDENTIFIER,
 *   parameters ANY DEFINED BY capabilityID OPTIONAL }
 * SMIMECapabilities ::= SEQUENCE OF SMIMECapability
 * </pre>
 * 
 * @see <a href="http://tools.ietf.org/html/rfc2633">RFC 2633</a>
 * @param bValue The octet string value
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 */
private String getSmimeCapabilitiesStringValue(byte[] bValue) throws IOException {
    SMIMECapabilities caps = SMIMECapabilities.getInstance(ASN1Primitive.fromByteArray(bValue));

    String sParams = RB.getString("SmimeParameters");

    StringBuilder sb = new StringBuilder();

    for (Object o : caps.getCapabilities(null)) {

        SMIMECapability cap = (SMIMECapability) o;

        String sCapId = cap.getCapabilityID().getId();
        String sCap = getRes(sCapId, "UnrecognisedSmimeCapability");

        if (sb.length() != 0) {
            sb.append("<br>");
        }
        sb.append("<ul><li>");
        sb.append(MessageFormat.format(sCap, sCapId));

        ASN1Encodable params;
        if ((params = cap.getParameters()) != null) {
            sb.append("<ul><li>");
            sb.append(sParams);
            sb.append(": ");
            sb.append(stringify(params));
            sb.append("</li></ul>");
        }

        sb.append("</li></ul>");
    }

    return sb.toString();
}