/** * return a CompressedData object from the given object. * * @param _obj the object we want converted. * @exception IllegalArgumentException if the object cannot be converted. */ public static CompressedData getInstance( Object _obj) { if (_obj == null || _obj instanceof CompressedData) { return (CompressedData)_obj; } if (_obj instanceof ASN1Sequence) { return new CompressedData((ASN1Sequence)_obj); } throw new IllegalArgumentException("Invalid CompressedData: " + _obj.getClass().getName()); }
/** Método que extrae el contenido de un tipo CompressedData. * @param data El tipo CompressedData. * @return El contenido del envoltorio. * @throws IOException Cuando hay un error de lectura de datos. * @throws DataFormatException Si los datos no estaban comprimidos. */ static byte[] getContentCompressedData(final byte[] data) throws IOException, DataFormatException { final ASN1Sequence contentEnvelopedData = Utils.fetchWrappedData(data); final CompressedData compressed = CompressedData.getInstance(contentEnvelopedData); final DEROctetString dos = (DEROctetString) compressed.getEncapContentInfo().getContent(); return BinaryUtils.uncompress(dos.getOctets()); } }
/** * Return a CompressedData object from a tagged object. * * @param ato the tagged object holding the object we want. * @param isExplicit true if the object is meant to be explicitly * tagged false otherwise. * @exception IllegalArgumentException if the object held by the * tagged object cannot be converted. */ public static CompressedData getInstance( ASN1TaggedObject ato, boolean isExplicit) { return getInstance(ASN1Sequence.getInstance(ato, isExplicit)); }
/** * Return the uncompressed content. * * @param expanderProvider a provider of expander algorithm implementations. * @return the uncompressed content * @throws CMSException if there is an exception un-compressing the data. */ public byte[] getContent(InputExpanderProvider expanderProvider) throws CMSException { ContentInfo content = comData.getEncapContentInfo(); ASN1OctetString bytes = (ASN1OctetString)content.getContent(); InputExpander expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier()); InputStream zIn = expander.getInputStream(bytes.getOctetStream()); try { return CMSUtils.streamToByteArray(zIn); } catch (IOException e) { throw new CMSException("exception reading compressed stream.", e); } }
/** * return a CompressedData object from a tagged object. * * @param _ato the tagged object holding the object we want. * @param _explicit true if the object is meant to be explicitly * tagged false otherwise. * @exception IllegalArgumentException if the object held by the * tagged object cannot be converted. */ public static CompressedData getInstance( ASN1TaggedObject _ato, boolean _explicit) { return getInstance(ASN1Sequence.getInstance(_ato, _explicit)); }
/** * Return the uncompressed content. * * @param expanderProvider a provider of expander algorithm implementations. * @return the uncompressed content * @throws CMSException if there is an exception un-compressing the data. */ public byte[] getContent(InputExpanderProvider expanderProvider) throws CMSException { ContentInfo content = comData.getEncapContentInfo(); ASN1OctetString bytes = (ASN1OctetString)content.getContent(); InputExpander expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier()); InputStream zIn = expander.getInputStream(bytes.getOctetStream()); try { return CMSUtils.streamToByteArray(zIn); } catch (IOException e) { throw new CMSException("exception reading compressed stream.", e); } }
/** * Return a CompressedData object from the given object. * <p> * Accepted inputs: * <ul> * <li> null → null * <li> {@link CompressedData} object * <li> {@link org.spongycastle.asn1.ASN1Sequence#getInstance(java.lang.Object) ASN1Sequence} input formats with CompressedData structure inside * </ul> * * @param obj the object we want converted. * @exception IllegalArgumentException if the object cannot be converted. */ public static CompressedData getInstance( Object obj) { if (obj instanceof CompressedData) { return (CompressedData)obj; } if (obj != null) { return new CompressedData(ASN1Sequence.getInstance(obj)); } return null; }
public CMSCompressedData( ContentInfo contentInfo) throws CMSException { this.contentInfo = contentInfo; try { this.comData = CompressedData.getInstance(contentInfo.getContent()); } catch (ClassCastException e) { throw new CMSException("Malformed content.", e); } catch (IllegalArgumentException e) { throw new CMSException("Malformed content.", e); } }
/** Obtiene un tipo CompressedData. * @param data * Datos a comprimir * @return Tipo CompressedData. * @throws IOException En caso de error en la lectura o tratamiento de datos */ static byte[] genCompressedData(final byte[] data) throws IOException { // Algoritmo de compresion final AlgorithmIdentifier comAlgId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(ZLIB)); // Se comprimen los datos final byte[] compressed = BinaryUtils.compress(data); final ASN1OctetString comOcts = new BEROctetString(compressed); // Contenido comprimido final ContentInfo comContent = new ContentInfo(CMSObjectIdentifiers.data, comOcts); return new ContentInfo(CMSObjectIdentifiers.compressedData, new CompressedData(comAlgId, comContent)).getEncoded(ASN1Encoding.DER); }
public CMSCompressedData( ContentInfo contentInfo) throws CMSException { this.contentInfo = contentInfo; try { this.comData = CompressedData.getInstance(contentInfo.getContent()); } catch (ClassCastException e) { throw new CMSException("Malformed content.", e); } catch (IllegalArgumentException e) { throw new CMSException("Malformed content.", e); } }
new CompressedData(comAlgId, comContent));
CompressedData.getInstance(compressedData);
new CompressedData(comAlgId, comContent));