private byte [ ] decode ( DerInputStream in ) throws IOException { DerValue val = in . getDerValue ( ) ; // save the DER encoding with its proper tag byte. byte [ ] derEncoding = val . toByteArray ( ) ; derEncoding [ 0 ] = DerValue . tag_SetOf ; DerInputStream derIn = new DerInputStream ( derEncoding ) ; DerValue [ ] derVals = derIn . getSet ( 3 , true ) ; PKCS9Attribute attrib ; ObjectIdentifier oid ; boolean reuseEncoding = true ; for ( int i = 0 ; i < derVals . length ; i ++ ) { try { attrib = new PKCS9Attribute ( derVals [ i ] ) ; } catch ( ParsingException e ) { if ( ignoreUnsupportedAttributes ) { reuseEncoding = false ; // cannot reuse supplied DER encoding continue ; // skip } else { throw e ; } } oid = attrib . getOID ( ) ; if ( attributes . get ( oid ) != null ) throw new IOException ( "Duplicate PKCS9 attribute: " + oid ) ; if ( permittedAttributes != null && ! permittedAttributes . containsKey ( oid ) ) throw new IOException ( "Attribute " + oid + " not permitted in this attribute set" ) ; attributes . put ( oid , attrib ) ; } return reuseEncoding ? derEncoding : generateDerEncoding ( ) ; }
Decode this set of PKCS9 attributes from the contents of its DER encoding . Ignores unsupported attributes when directed .