byte [ ] convert ( byte [ ] indefData ) throws IOException { data = indefData ; dataPos = 0 ; index = 0 ; dataSize = data . length ; int len = 0 ; int unused = 0 ; // parse and set up the vectors of all the indefinite-lengths while ( dataPos < dataSize ) { parseTag ( ) ; len = parseLength ( ) ; parseValue ( len ) ; if ( unresolved == 0 ) { unused = dataSize - dataPos ; dataSize = dataPos ; break ; } } if ( unresolved != 0 ) { throw new IOException ( "not all indef len BER resolved" ) ; } newData = new byte [ dataSize + numOfTotalLenBytes + unused ] ; dataPos = 0 ; newDataPos = 0 ; index = 0 ; // write out the new byte array replacing all the indefinite-lengths // and EOCs while ( dataPos < dataSize ) { writeTag ( ) ; writeLengthAndValue ( ) ; } System . arraycopy ( indefData , dataSize , newData , dataSize + numOfTotalLenBytes , unused ) ; return newData ; }
Converts a indefinite length DER encoded byte array to a definte length DER encoding .