本文整理汇总了Java中org.bouncycastle.asn1.DERApplicationSpecific.isConstructed方法的典型用法代码示例。如果您正苦于以下问题:Java DERApplicationSpecific.isConstructed方法的具体用法?Java DERApplicationSpecific.isConstructed怎么用?Java DERApplicationSpecific.isConstructed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.asn1.DERApplicationSpecific
的用法示例。
在下文中一共展示了DERApplicationSpecific.isConstructed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeTag
import org.bouncycastle.asn1.DERApplicationSpecific; //导入方法依赖的package包/类
public static int encodeTag(DERApplicationSpecific spec)
{
int retValue = BERTags.APPLICATION;
boolean constructed = spec.isConstructed();
if (constructed)
{
retValue |= BERTags.CONSTRUCTED;
}
int tag = spec.getApplicationTag();
if (tag > 31)
{
retValue |= 0x1F;
retValue <<= 8;
int currentByte = tag & 0x7F;
retValue |= currentByte;
tag >>= 7;
while (tag > 0)
{
retValue |= 0x80;
retValue <<= 8;
currentByte = tag & 0x7F;
tag >>= 7;
}
}
else
{
retValue |= tag;
}
return retValue;
}
示例2: performTest
import org.bouncycastle.asn1.DERApplicationSpecific; //导入方法依赖的package包/类
public void performTest()
throws Exception
{
DERInteger value = new DERInteger(9);
DERApplicationSpecific tagged = new DERApplicationSpecific(false, 3, value);
if (!areEqual(impData, tagged.getEncoded()))
{
fail("implicit encoding failed");
}
DERInteger recVal = (DERInteger)tagged.getObject(BERTags.INTEGER);
if (!value.equals(recVal))
{
fail("implicit read back failed");
}
DERApplicationSpecific certObj = (DERApplicationSpecific)
ASN1Primitive.fromByteArray(certData);
if (!certObj.isConstructed() || certObj.getApplicationTag() != 33)
{
fail("parsing of certificate data failed");
}
byte[] encoded = certObj.getEncoded(ASN1Encoding.DER);
if (!Arrays.areEqual(certData, encoded))
{
fail("re-encoding of certificate data failed");
}
}
示例3: performTest
import org.bouncycastle.asn1.DERApplicationSpecific; //导入方法依赖的package包/类
public void performTest()
throws Exception
{
testTaggedObject();
DERApplicationSpecific appSpec = (DERApplicationSpecific)ASN1Primitive.fromByteArray(sampleData);
if (1 != appSpec.getApplicationTag())
{
fail("wrong tag detected");
}
ASN1Integer value = new ASN1Integer(9);
DERApplicationSpecific tagged = new DERApplicationSpecific(false, 3, value);
if (!areEqual(impData, tagged.getEncoded()))
{
fail("implicit encoding failed");
}
ASN1Integer recVal = (ASN1Integer)tagged.getObject(BERTags.INTEGER);
if (!value.equals(recVal))
{
fail("implicit read back failed");
}
DERApplicationSpecific certObj = (DERApplicationSpecific)
ASN1Primitive.fromByteArray(certData);
if (!certObj.isConstructed() || certObj.getApplicationTag() != 33)
{
fail("parsing of certificate data failed");
}
byte[] encoded = certObj.getEncoded(ASN1Encoding.DER);
if (!Arrays.areEqual(certData, encoded))
{
fail("re-encoding of certificate data failed");
}
}
示例4: parse
import org.bouncycastle.asn1.DERApplicationSpecific; //导入方法依赖的package包/类
@Override
protected void parse ( byte[] token ) throws IOException {
try ( ASN1InputStream is = new ASN1InputStream(token) ) {
DERApplicationSpecific constructed = (DERApplicationSpecific) is.readObject();
if ( constructed == null || !constructed.isConstructed() )
throw new IOException(
"Malformed SPNEGO token " + constructed
+ ( constructed != null ? " " + constructed.isConstructed() + " " + constructed.getApplicationTag() : "" ));
try ( ASN1InputStream der = new ASN1InputStream(constructed.getContents()) ) {
ASN1ObjectIdentifier spnego = (ASN1ObjectIdentifier) der.readObject();
if ( !SPNEGO_OID.equals(spnego) ) {
throw new IOException("Malformed SPNEGO token, OID " + spnego);
}
ASN1TaggedObject tagged = (ASN1TaggedObject) der.readObject();
if ( tagged.getTagNo() != 0 ) {
throw new IOException("Malformed SPNEGO token: tag " + tagged.getTagNo() + " " + tagged);
}
ASN1Sequence sequence = ASN1Sequence.getInstance(tagged, true);
Enumeration<ASN1Object> fields = sequence.getObjects();
while ( fields.hasMoreElements() ) {
tagged = (ASN1TaggedObject) fields.nextElement();
switch ( tagged.getTagNo() ) {
case 0:
sequence = ASN1Sequence.getInstance(tagged, true);
ASN1ObjectIdentifier[] mechs = new ASN1ObjectIdentifier[sequence.size()];
for ( int i = mechs.length - 1; i >= 0; i-- ) {
mechs[ i ] = (ASN1ObjectIdentifier) sequence.getObjectAt(i);
}
setMechanisms(mechs);
break;
case 1:
DERBitString ctxFlags = DERBitString.getInstance(tagged, true);
setContextFlags(ctxFlags.getBytes()[ 0 ] & 0xff);
break;
case 2:
ASN1OctetString mechanismToken = ASN1OctetString.getInstance(tagged, true);
setMechanismToken(mechanismToken.getOctets());
break;
case 3:
if ( ! ( tagged.getObject() instanceof DEROctetString ) ) {
break;
}
case 4:
ASN1OctetString mechanismListMIC = ASN1OctetString.getInstance(tagged, true);
setMechanismListMIC(mechanismListMIC.getOctets());
break;
default:
throw new IOException("Malformed token field.");
}
}
}
}
}
示例5: KerberosApRequest
import org.bouncycastle.asn1.DERApplicationSpecific; //导入方法依赖的package包/类
public KerberosApRequest ( byte[] token, KerberosKey[] keys ) throws PACDecodingException {
if ( token.length <= 0 )
throw new PACDecodingException("Empty kerberos ApReq");
DLSequence sequence;
try {
try ( ASN1InputStream stream = new ASN1InputStream(new ByteArrayInputStream(token)) ) {
sequence = ASN1Util.as(DLSequence.class, stream);
}
}
catch ( IOException e ) {
throw new PACDecodingException("Malformed Kerberos Ticket", e);
}
Enumeration<?> fields = sequence.getObjects();
while ( fields.hasMoreElements() ) {
ASN1TaggedObject tagged = ASN1Util.as(ASN1TaggedObject.class, fields.nextElement());
switch ( tagged.getTagNo() ) {
case 0:
ASN1Integer pvno = ASN1Util.as(ASN1Integer.class, tagged);
if ( !pvno.getValue().equals(new BigInteger(KerberosConstants.KERBEROS_VERSION)) ) {
throw new PACDecodingException("Invalid kerberos version");
}
break;
case 1:
ASN1Integer msgType = ASN1Util.as(ASN1Integer.class, tagged);
if ( !msgType.getValue().equals(new BigInteger(KerberosConstants.KERBEROS_AP_REQ)) )
throw new PACDecodingException("Invalid kerberos request");
break;
case 2:
DERBitString bitString = ASN1Util.as(DERBitString.class, tagged);
this.apOptions = bitString.getBytes()[ 0 ];
break;
case 3:
DERApplicationSpecific derTicket = ASN1Util.as(DERApplicationSpecific.class, tagged);
if ( !derTicket.isConstructed() )
throw new PACDecodingException("Malformed Kerberos Ticket");
this.ticket = new KerberosTicket(derTicket.getContents(), this.apOptions, keys);
break;
case 4:
// Let's ignore this for now
break;
default:
throw new PACDecodingException("Invalid field in kerberos ticket");
}
}
}