private static byte[] getBytesOfHexString(COSString s) { if (s == null) { return null; } return s.get(); }
/** * Constructor for child classes * @param cosString is greenfield COSString. * @param type child class type. */ public GFCosString(COSString cosString, final String type) { super(cosString, type); this.value = cosString.get(); this.isHex = cosString.isHexadecimal(); this.containsOnlyHex = cosString.isContainsOnlyHex(); this.hexCount = cosString.getHexCount(); }
@Override public InputStream getData() { if (signature != null && !signature.empty()) { COSString contents = signature.getContents(); return contents == null ? null : new ByteArrayInputStream(contents.get()); } return null; }
private static void addArrayElements(List<byte[]> res, COSArray arg) { for (COSObject element : arg) { if (element != null && element.getType() == COSObjType.COS_STRING) { res.add(((COSString) element.getDirectBase()).get()); } } }
/** * @param pkcsData {@link COSString} containing encoded PKCS#7 object. */ public GFPKCSDataObject(COSString pkcsData) { super(PKCS_DATA_OBJECT_TYPE); try { if (!pkcsData.isHexadecimal()) { pkcs7 = new PKCS7(pkcsData.get()); } else { byte[] decodedData = pkcsData.get(); pkcs7 = new PKCS7(decodedData); } } catch (IOException e) { LOGGER.log(Level.FINE, "Passed PKCS7 object can't be read", e); pkcs7 = getEmptyPKCS7(); } }
private static List<byte[]> getStrings(List<COSBase> stringArgs) { if (!stringArgs.isEmpty()) { List<byte[]> res = new ArrayList<>(); COSBase arg = stringArgs.get(0); if (arg != null) { if (arg.getType() == COSObjType.COS_ARRAY) { GFOpTextShow.addArrayElements(res, (COSArray) arg.getDirectBase()); } else { if (arg.getType() == COSObjType.COS_STRING) { res.add(((COSString) (arg.getDirectBase())).get()); } } } return res; } return Collections.emptyList(); }
private static String getTrailerID(COSObject ids) { if (ids != null && ids.getType() == COSObjType.COS_ARRAY) { COSArray idArray = (COSArray) ids.getDirectBase(); StringBuilder builder = new StringBuilder(); for (COSObject id : idArray) { if (id.getType() == COSObjType.COS_STRING) { for (byte aByte : ((COSString) id.getDirectBase()).get()) { builder.append((char) (aByte & 0xFF)); } } else { LOGGER.log(Level.SEVERE, "Value of ID key is not a string. Ignoring ID"); } } // need to discard last whitespace return builder.toString(); } return null; }
public void visitFromString(COSString obj) { this.copy.assign(COSString.construct(obj.get(), obj.isHexadecimal())); }