コード例 #1
0
ファイル: Checksum.java プロジェクト: ronshapiro/j86
 /**
  * Encodes a Checksum object. <xmp> Checksum ::= SEQUENCE { cksumtype [0] Int32, checksum [1]
  * OCTET STRING } </xmp>
  *
  * <p>This definition reflects the Network Working Group RFC 4120 specification available at <a
  * href="http://www.ietf.org/rfc/rfc4120.txt">http://www.ietf.org/rfc/rfc4120.txt</a>.
  *
  * @return byte array of enocded Checksum.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 public byte[] asn1Encode() throws Asn1Exception, IOException {
   DerOutputStream bytes = new DerOutputStream();
   DerOutputStream temp = new DerOutputStream();
   temp.putInteger(BigInteger.valueOf(cksumType));
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
   temp = new DerOutputStream();
   temp.putOctetString(checksum);
   bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
   temp = new DerOutputStream();
   temp.write(DerValue.tag_Sequence, bytes);
   return temp.toByteArray();
 }
コード例 #2
0
ファイル: Checksum.java プロジェクト: ronshapiro/j86
  /**
   * Parse (unmarshal) a checksum object from a DER input stream. This form parsing might be used
   * when expanding a value which is part of a constructed sequence and uses explicitly tagged type.
   *
   * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
   * @exception IOException if an I/O error occurs while reading encoded data.
   * @param data the Der input stream value, which contains one or more marshaled value.
   * @param explicitTag tag number.
   * @param optional indicates if this data field is optional
   * @return an instance of Checksum.
   */
  public static Checksum parse(DerInputStream data, byte explicitTag, boolean optional)
      throws Asn1Exception, IOException {

    if ((optional) && (((byte) data.peekByte() & (byte) 0x1F) != explicitTag)) {
      return null;
    }
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte) 0x1F)) {
      throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    } else {
      DerValue subDer = der.getData().getDerValue();
      return new Checksum(subDer);
    }
  }
コード例 #3
0
ファイル: Checksum.java プロジェクト: ronshapiro/j86
 /**
  * Constructs an instance of Checksum from an ASN.1 encoded representation.
  *
  * @param encoding a single DER-encoded value.
  * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
  * @exception IOException if an I/O error occurs while reading encoded data.
  */
 private Checksum(DerValue encoding) throws Asn1Exception, IOException {
   DerValue der;
   if (encoding.getTag() != DerValue.tag_Sequence) {
     throw new Asn1Exception(Krb5.ASN1_BAD_ID);
   }
   der = encoding.getData().getDerValue();
   if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) {
     cksumType = der.getData().getBigInteger().intValue();
   } else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
   der = encoding.getData().getDerValue();
   if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) {
     checksum = der.getData().getOctetString();
   } else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
   if (encoding.getData().available() > 0) {
     throw new Asn1Exception(Krb5.ASN1_BAD_ID);
   }
 }