public static Asn1Sequence GetInstance(Asn1TaggedObject obj, bool explicitly) { Asn1Object @object = obj.GetObject(); if (explicitly) { if (!obj.IsExplicit()) { throw new ArgumentException("object implicit - explicit expected."); } return((Asn1Sequence)@object); } if (obj.IsExplicit()) { if (obj is BerTaggedObject) { return(new BerSequence(@object)); } return(new DerSequence(@object)); } if (@object is Asn1Sequence) { return((Asn1Sequence)@object); } throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj"); }
public static Asn1Set GetInstance(Asn1TaggedObject obj, bool explicitly) { Asn1Object @object = obj.GetObject(); if (explicitly) { if (!obj.IsExplicit()) { throw new ArgumentException("object implicit - explicit expected."); } return((Asn1Set)@object); } if (obj.IsExplicit()) { return(new DerSet(@object)); } if (@object is Asn1Set) { return((Asn1Set)@object); } if (@object is Asn1Sequence) { Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(); Asn1Sequence asn1Sequence = (Asn1Sequence)@object; foreach (Asn1Encodable item in asn1Sequence) { asn1EncodableVector.Add(item); } return(new DerSet(asn1EncodableVector, needsSorting: false)); } throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj"); }
private DSTU4145ECBinary(Asn1Sequence seq) { int index = 0; if (seq.GetObjectAt(index) is Asn1TaggedObject) { Asn1TaggedObject taggedVersion = (Asn1TaggedObject)seq.GetObjectAt(index); if (taggedVersion.IsExplicit() && 0 == taggedVersion.TagNo) { version = DerInteger.GetInstance(taggedVersion.GetObject()).Value; index++; } else { throw new ArgumentException("object parse error"); } } f = DSTU4145BinaryField.GetInstance(seq.GetObjectAt(index)); index++; a = DerInteger.GetInstance(seq.GetObjectAt(index)); index++; b = Asn1OctetString.GetInstance(seq.GetObjectAt(index)); index++; n = DerInteger.GetInstance(seq.GetObjectAt(index)); index++; bp = Asn1OctetString.GetInstance(seq.GetObjectAt(index)); }
internal static bool IsConstructed(bool isExplicit, Asn1Object obj) { if (isExplicit || obj is Asn1Sequence || obj is Asn1Set) { return(true); } Asn1TaggedObject asn1TaggedObject = obj as Asn1TaggedObject; if (asn1TaggedObject == null) { return(false); } return(IsConstructed(asn1TaggedObject.IsExplicit(), asn1TaggedObject.GetObject())); }
private ContentInfo(Asn1Sequence seq) { if (seq.Count < 1 || seq.Count > 2) { throw new ArgumentException("Bad sequence size: " + seq.Count, "seq"); } contentType = (DerObjectIdentifier)seq[0]; if (seq.Count > 1) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[1]; if (!asn1TaggedObject.IsExplicit() || asn1TaggedObject.TagNo != 0) { throw new ArgumentException("Bad tag for 'content'", "seq"); } content = asn1TaggedObject.GetObject(); } }
public SignerLocation(Asn1Sequence seq) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) global::System.Collections.IEnumerator enumerator = seq.GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)enumerator.get_Current(); switch (asn1TaggedObject.TagNo) { case 0: countryName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true); break; case 1: localityName = DerUtf8String.GetInstance(asn1TaggedObject, isExplicit: true); break; case 2: { bool explicitly = asn1TaggedObject.IsExplicit(); postalAddress = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly); if (postalAddress != null && postalAddress.Count > 6) { throw new ArgumentException("postal address must contain less than 6 strings"); } break; } default: throw new ArgumentException("illegal tag"); } } } finally { global::System.IDisposable disposable = enumerator as global::System.IDisposable; if (disposable != null) { disposable.Dispose(); } } }
private ContentInfo(Asn1Sequence seq) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) if (seq.Count < 1 || seq.Count > 2) { throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count), "seq"); } contentType = (DerObjectIdentifier)seq[0]; if (seq.Count > 1) { Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[1]; if (!asn1TaggedObject.IsExplicit() || asn1TaggedObject.TagNo != 0) { throw new ArgumentException("Bad tag for 'content'", "seq"); } content = asn1TaggedObject.GetObject(); } }
private KekRecipientInfo GetKekInfo( Asn1TaggedObject o) { // For compatibility with erroneous version, we don't always pass 'false' here return(KekRecipientInfo.GetInstance(o, o.IsExplicit())); }
private KekRecipientInfo GetKekInfo(Asn1TaggedObject o) { return(KekRecipientInfo.GetInstance(o, o.IsExplicit())); }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static void AsString( string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string tab = indent + Tab; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence" + (obj as DerSequence).ToString()); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Sequence)obj)) { if (o == null || o is Asn1Null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is Asn1TaggedObject) { string tab = indent + Tab; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } Asn1TaggedObject o = (Asn1TaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); if (!o.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (o.IsEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(tab, verbose, o.GetObject(), buf); } } else if (obj is BerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : Hex.ToHexString(octets); buf.Append(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : Hex.ToHexString(octets); buf.Append(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerBitString) { DerBitString bt = (DerBitString)obj; byte[] bytes = bt.GetBytes(); string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerGraphicString) { buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine); } else if (obj is DerVideotexString) { buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated en = (DerEnumerated)obj; buf.Append(indent + "DER Enumerated(" + en.Value + ")" + NewLine); } else if (obj is DerExternal) { DerExternal ext = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string tab = indent + Tab; if (ext.DirectReference != null) { buf.Append(tab + "Direct Reference: " + ext.DirectReference.Id + NewLine); } if (ext.IndirectReference != null) { buf.Append(tab + "Indirect Reference: " + ext.IndirectReference.ToString() + NewLine); } if (ext.DataValueDescriptor != null) { AsString(tab, verbose, ext.DataValueDescriptor, buf); } buf.Append(tab + "Encoding: " + ext.Encoding + NewLine); AsString(tab, verbose, ext.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } }
private KekRecipientInfo GetKekInfo( Asn1TaggedObject o) { // For compatibility with erroneous version, we don't always pass 'false' here return KekRecipientInfo.GetInstance(o, o.IsExplicit()); }