Search in sources :

Example 51 with COSString

use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.

the class PDSeedValueCertificate method setIssuer.

/**
 * (Optional) A list of array of bytes containing DER-encoded X.509v3 certificates of acceptable
 * issuers. If the signer’s certificate chains up to any of the specified issuers (either
 * directly or indirectly), the certificate is considered acceptable for signing.
 *
 * @param issuers A list of byte array containing DER-encoded X.509v3 certificates
 */
public void setIssuer(List<byte[]> issuers) {
    COSArray array = new COSArray();
    for (byte[] issuer : issuers) {
        array.add(new COSString(issuer));
    }
    this.dictionary.setItem(COSName.ISSUER, array);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 52 with COSString

use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.

the class PDSeedValueCertificate method getKeyUsage.

/**
 * Returns list of key usages of certificate strings where each string is 9 characters long and each character is
 * one of these values {0, 1, X} 0 for must not set, 1 for must set, X for don't care. each index in the string
 * represents a key usage:
 * <ol>
 * <li>digitalSignature</li>
 * <li>non-Repudiation</li>
 * <li>keyEncipherment</li>
 * <li>dataEncipherment</li>
 * <li>keyAgreement</li>
 * <li>keyCertSign</li>
 * <li>cRLSign</li>
 * <li>encipherOnly</li>
 * <li>decipherOnly</li>
 * </ol>
 *
 * @return list of key usages
 */
public List<String> getKeyUsage() {
    COSBase base = this.dictionary.getDictionaryObject(COSName.KEY_USAGE);
    if (base instanceof COSArray) {
        COSArray array = (COSArray) base;
        List<String> keyUsageExtensions = new LinkedList<String>();
        for (COSBase item : array) {
            if (item instanceof COSString) {
                keyUsageExtensions.add(((COSString) item).getString());
            }
        }
        return keyUsageExtensions;
    }
    return null;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString) LinkedList(java.util.LinkedList)

Example 53 with COSString

use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.

the class PDSeedValueCertificate method addSubject.

/**
 * (Optional) byte array containing DER-encoded X.509v3 certificate that is acceptable for
 * signing. works like {@link #setSubject(List)} but one byte array
 *
 * @param subject byte array containing DER-encoded X.509v3 certificate
 */
public void addSubject(byte[] subject) {
    COSBase base = this.dictionary.getDictionaryObject(COSName.SUBJECT);
    COSArray array;
    if (base instanceof COSArray) {
        array = (COSArray) base;
    } else {
        array = new COSArray();
    }
    COSString string = new COSString(subject);
    array.add(string);
    this.dictionary.setItem(COSName.SUBJECT, array);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 54 with COSString

use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.

the class PDSeedValueCertificate method setSubjectDN.

/**
 * (Optional; PDF 1.7) A list of maps, where each map contains key value pairs, that specify the
 * Subject Distinguished Name (DN) that must be present within the certificate for it to be
 * acceptable for signing. The certificate must at a minimum contain all the attributes
 * specified in one of the maps entered.
 *
 * @param subjectDN list of maps that contains subject distinguished names
 */
public void setSubjectDN(List<Map<String, String>> subjectDN) {
    List<COSDictionary> subjectDNDict = new LinkedList<COSDictionary>();
    for (Map<String, String> subjectDNItem : subjectDN) {
        COSDictionary dict = new COSDictionary();
        for (Map.Entry<String, String> entry : subjectDNItem.entrySet()) {
            dict.setItem(entry.getKey(), new COSString(entry.getValue()));
        }
        subjectDNDict.add(dict);
    }
    this.dictionary.setItem(COSName.SUBJECT_DN, COSArrayList.converterToCOSArray(subjectDNDict));
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSString(com.tom_roush.pdfbox.cos.COSString) Map(java.util.Map) HashMap(java.util.HashMap) COSString(com.tom_roush.pdfbox.cos.COSString) LinkedList(java.util.LinkedList)

Example 55 with COSString

use of com.tom_roush.pdfbox.cos.COSString in project PdfBox-Android by TomRoush.

the class PDSeedValueCertificate method addOID.

/**
 * works like {@link #setOID(List)} but for one object
 *
 * @param oid the object identifier.
 */
public void addOID(byte[] oid) {
    COSBase base = this.dictionary.getDictionaryObject(COSName.OID);
    COSArray array;
    if (base instanceof COSArray) {
        array = (COSArray) base;
    } else {
        array = new COSArray();
    }
    COSString string = new COSString(oid);
    array.add(string);
    this.dictionary.setItem(COSName.OID, array);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString)

Aggregations

COSString (com.tom_roush.pdfbox.cos.COSString)65 COSArray (com.tom_roush.pdfbox.cos.COSArray)33 COSBase (com.tom_roush.pdfbox.cos.COSBase)24 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)5 COSName (com.tom_roush.pdfbox.cos.COSName)5 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)4 Map (java.util.Map)4 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)2 MessageDigest (java.security.MessageDigest)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1