|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
/* |
|
* |
|
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
*/ |
|
|
|
package sun.security.krb5.internal; |
|
|
|
import sun.security.util.*; |
|
import sun.security.krb5.Asn1Exception; |
|
import java.io.IOException; |
|
import java.math.BigInteger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class MethodData { |
|
private int methodType; |
|
private byte[] methodData = null; |
|
|
|
public MethodData(int type, byte[] data) { |
|
methodType = type; |
|
if (data != null) { |
|
methodData = data.clone(); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public MethodData(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() & 0x1F) == 0x00) { |
|
BigInteger bint = der.getData().getBigInteger(); |
|
methodType = bint.intValue(); |
|
} |
|
else |
|
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
if (encoding.getData().available() > 0) { |
|
der = encoding.getData().getDerValue(); |
|
if ((der.getTag() & 0x1F) == 0x01) { |
|
methodData = der.getData().getOctetString(); |
|
} |
|
else throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
} |
|
if (encoding.getData().available() > 0) |
|
throw new Asn1Exception(Krb5.ASN1_BAD_ID); |
|
} |
|
|
|
/** |
|
* Encodes an MethodData object. |
|
* @return the byte array of encoded MethodData object. |
|
* @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(methodType)); |
|
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp); |
|
if (methodData != null) { |
|
temp = new DerOutputStream(); |
|
temp.putOctetString(methodData); |
|
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp); |
|
} |
|
|
|
temp = new DerOutputStream(); |
|
temp.write(DerValue.tag_Sequence, bytes); |
|
return temp.toByteArray(); |
|
} |
|
|
|
} |