< prev index next >

src/java.base/share/classes/sun/security/pkcs/SignerInfo.java

Print this page




 163             if (derin.available() != 0
 164                 && (byte)(derin.peekByte()) == (byte)0xA1) {
 165                 unauthenticatedAttributes =
 166                     new PKCS9Attributes(derin, true);// ignore unsupported attrs
 167             }
 168         }
 169 
 170         // all done
 171         if (derin.available() != 0) {
 172             throw new ParsingException("extra data at the end");
 173         }
 174     }
 175 
 176     public void encode(DerOutputStream out) throws IOException {
 177 
 178         derEncode(out);
 179     }
 180 
 181     /**
 182      * DER encode this object onto an output stream.
 183      * Implements the <code>DerEncoder</code> interface.
 184      *
 185      * @param out
 186      * the output stream on which to write the DER encoding.
 187      *
 188      * @exception IOException on encoding error.
 189      */
 190     public void derEncode(OutputStream out) throws IOException {
 191         DerOutputStream seq = new DerOutputStream();
 192         seq.putInteger(version);
 193         DerOutputStream issuerAndSerialNumber = new DerOutputStream();
 194         issuerName.encode(issuerAndSerialNumber);
 195         issuerAndSerialNumber.putInteger(certificateSerialNumber);
 196         seq.write(DerValue.tag_Sequence, issuerAndSerialNumber);
 197 
 198         digestAlgorithmId.encode(seq);
 199 
 200         // encode authenticated attributes if there are any
 201         if (authenticatedAttributes != null)
 202             authenticatedAttributes.encode((byte)0xA0, seq);
 203 


 437     public PKCS9Attributes getAuthenticatedAttributes() {
 438         return authenticatedAttributes;
 439     }
 440 
 441     public AlgorithmId getDigestEncryptionAlgorithmId() {
 442         return digestEncryptionAlgorithmId;
 443     }
 444 
 445     public byte[] getEncryptedDigest() {
 446         return encryptedDigest;
 447     }
 448 
 449     public PKCS9Attributes getUnauthenticatedAttributes() {
 450         return unauthenticatedAttributes;
 451     }
 452 
 453     /*
 454      * Extracts a timestamp from a PKCS7 SignerInfo.
 455      *
 456      * Examines the signer's unsigned attributes for a
 457      * <tt>signatureTimestampToken</tt> attribute. If present,
 458      * then it is parsed to extract the date and time at which the
 459      * timestamp was generated.
 460      *
 461      * @param info A signer information element of a PKCS 7 block.
 462      *
 463      * @return A timestamp token or null if none is present.
 464      * @throws IOException if an error is encountered while parsing the
 465      *         PKCS7 data.
 466      * @throws NoSuchAlgorithmException if an error is encountered while
 467      *         verifying the PKCS7 object.
 468      * @throws SignatureException if an error is encountered while
 469      *         verifying the PKCS7 object.
 470      * @throws CertificateException if an error is encountered while generating
 471      *         the TSA's certpath.
 472      */
 473     public Timestamp getTimestamp()
 474         throws IOException, NoSuchAlgorithmException, SignatureException,
 475                CertificateException
 476     {
 477         if (timestamp != null || !hasTimestamp)




 163             if (derin.available() != 0
 164                 && (byte)(derin.peekByte()) == (byte)0xA1) {
 165                 unauthenticatedAttributes =
 166                     new PKCS9Attributes(derin, true);// ignore unsupported attrs
 167             }
 168         }
 169 
 170         // all done
 171         if (derin.available() != 0) {
 172             throw new ParsingException("extra data at the end");
 173         }
 174     }
 175 
 176     public void encode(DerOutputStream out) throws IOException {
 177 
 178         derEncode(out);
 179     }
 180 
 181     /**
 182      * DER encode this object onto an output stream.
 183      * Implements the {@code DerEncoder} interface.
 184      *
 185      * @param out
 186      * the output stream on which to write the DER encoding.
 187      *
 188      * @exception IOException on encoding error.
 189      */
 190     public void derEncode(OutputStream out) throws IOException {
 191         DerOutputStream seq = new DerOutputStream();
 192         seq.putInteger(version);
 193         DerOutputStream issuerAndSerialNumber = new DerOutputStream();
 194         issuerName.encode(issuerAndSerialNumber);
 195         issuerAndSerialNumber.putInteger(certificateSerialNumber);
 196         seq.write(DerValue.tag_Sequence, issuerAndSerialNumber);
 197 
 198         digestAlgorithmId.encode(seq);
 199 
 200         // encode authenticated attributes if there are any
 201         if (authenticatedAttributes != null)
 202             authenticatedAttributes.encode((byte)0xA0, seq);
 203 


 437     public PKCS9Attributes getAuthenticatedAttributes() {
 438         return authenticatedAttributes;
 439     }
 440 
 441     public AlgorithmId getDigestEncryptionAlgorithmId() {
 442         return digestEncryptionAlgorithmId;
 443     }
 444 
 445     public byte[] getEncryptedDigest() {
 446         return encryptedDigest;
 447     }
 448 
 449     public PKCS9Attributes getUnauthenticatedAttributes() {
 450         return unauthenticatedAttributes;
 451     }
 452 
 453     /*
 454      * Extracts a timestamp from a PKCS7 SignerInfo.
 455      *
 456      * Examines the signer's unsigned attributes for a
 457      * {@code signatureTimestampToken} attribute. If present,
 458      * then it is parsed to extract the date and time at which the
 459      * timestamp was generated.
 460      *
 461      * @param info A signer information element of a PKCS 7 block.
 462      *
 463      * @return A timestamp token or null if none is present.
 464      * @throws IOException if an error is encountered while parsing the
 465      *         PKCS7 data.
 466      * @throws NoSuchAlgorithmException if an error is encountered while
 467      *         verifying the PKCS7 object.
 468      * @throws SignatureException if an error is encountered while
 469      *         verifying the PKCS7 object.
 470      * @throws CertificateException if an error is encountered while generating
 471      *         the TSA's certpath.
 472      */
 473     public Timestamp getTimestamp()
 474         throws IOException, NoSuchAlgorithmException, SignatureException,
 475                CertificateException
 476     {
 477         if (timestamp != null || !hasTimestamp)


< prev index next >