public static void Pkcs9AttributeCopyFromAsnNotAPkcs9Attribute() { // Pkcs9AttributeObject.CopyFrom(AsnEncodedData) refuses to accept any AsnEncodedData that isn't a Pkcs9AttributeObject-derived class. Pkcs9AttributeObject p = new Pkcs9AttributeObject(); byte[] rawData = "041e4d00790020004400650073006300720069007000740069006f006e000000".HexToByteArray(); AsnEncodedData a = new AsnEncodedData(Oids.DocumentName, rawData); Assert.Throws<ArgumentException>(() => p.CopyFrom(a)); }
public void ConstructorOidArray () { Oid o = new Oid (defaultOid); Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]); Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName"); Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value"); Assert.AreEqual (0, a.RawData.Length, "RawData"); }
public static void Pkcs9AttributeAsnEncodedDataCtorEmptyOidValue() { Oid oid = new Oid(Oids.Aes128); oid.Value = string.Empty; AsnEncodedData a = new AsnEncodedData(oid, new byte[3]); object ign; Assert.Throws<ArgumentException>(() => ign = new Pkcs9AttributeObject(a)); }
public override void CopyFrom(AsnEncodedData asnEncodedData) { if (asnEncodedData == null) { throw new ArgumentNullException("asnEncodedData"); } Pkcs9AttributeObject att = asnEncodedData as Pkcs9AttributeObject; if (att == null) { throw new ArgumentException(SecurityResources.GetResourceString("Cryptography_Pkcs9_AttributeMismatch")); } base.CopyFrom(asnEncodedData); }
internal static AsnEncodedDataCollection GetAsnEncodedDataCollection(System.Security.Cryptography.CAPI.CRYPT_ATTRIBUTE cryptAttribute) { AsnEncodedDataCollection datas = new AsnEncodedDataCollection(); Oid oid = new Oid(cryptAttribute.pszObjId); string name = oid.Value; for (uint i = 0; i < cryptAttribute.cValue; i++) { IntPtr pBlob = new IntPtr(((long)cryptAttribute.rgValue) + (i * Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB)))); Pkcs9AttributeObject asnEncodedData = new Pkcs9AttributeObject(oid, System.Security.Cryptography.CAPI.BlobToByteArray(pBlob)); Pkcs9AttributeObject obj3 = CryptoConfig.CreateFromName(name) as Pkcs9AttributeObject; if (obj3 != null) { obj3.CopyFrom(asnEncodedData); asnEncodedData = obj3; } datas.Add(asnEncodedData); } return(datas); }
public void ConstructorOidArrayNull () { Oid o = new Oid (defaultOid); Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, null); }
public static void MessageDigestFromRawData() { byte[] messageDigest = { 3, 45, 88, 128, 93 }; List<byte> encodedMessageDigestList = new List<byte>(messageDigest.Length + 2); encodedMessageDigestList.Add(4); encodedMessageDigestList.Add(checked((byte)(messageDigest.Length))); encodedMessageDigestList.AddRange(messageDigest); byte[] encodedMessageDigest = encodedMessageDigestList.ToArray(); Pkcs9MessageDigest p = new Pkcs9MessageDigest(); Pkcs9AttributeObject pAttribute = new Pkcs9AttributeObject(s_OidMessageDigest, encodedMessageDigest); p.CopyFrom(pAttribute); Assert.Equal<byte>(encodedMessageDigest, p.RawData); Assert.Equal<byte>(messageDigest, p.MessageDigest); string oid = p.Oid.Value; Assert.Equal(s_OidMessageDigest, oid); }
public void ConstructorOidNullArray () { Oid o = null; Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]); }
public void ConstructorEmpty () { Pkcs9AttributeObject a = new Pkcs9AttributeObject (); Assert.IsNull (a.Oid, "Oid"); Assert.IsNull (a.RawData, "RawData"); }
public void ConstructorAsnEncodedDataNull () { Pkcs9AttributeObject a = new Pkcs9AttributeObject (null); }
public void CopyFrom_SigningTime_OidRaw () { Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow); Pkcs9AttributeObject a = new Pkcs9AttributeObject (); a.CopyFrom (new AsnEncodedData (st.Oid, st.RawData)); }
public void CopyFrom_Self () { Pkcs9AttributeObject a = new Pkcs9AttributeObject ("1.2.3.4", new byte[2] { 0x05, 0x00 } ); a.CopyFrom (new AsnEncodedData (a.Oid, a.RawData)); }
public static void TestUnprotectedAttributes1_MessageDigest_RoundTrip() { byte[] rawData = "0405032d58805d".HexToByteArray(); Pkcs9AttributeObject pkcs9MessageDigest = new Pkcs9AttributeObject(Oids.MessageDigest, rawData); byte[] encodedMessage = CreateEcmsWithAttributes(pkcs9MessageDigest); VerifyUnprotectedAttributes1_MessageDigest(encodedMessage); }
public void ConstructorStringArrayNull () { Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, null); }
public void ConstructorStringNullArray () { string s = null; Pkcs9AttributeObject a = new Pkcs9AttributeObject (s, new byte[0]); }
public static void Pkcs9AttributeObjectNullaryCtor() { Pkcs9AttributeObject p = new Pkcs9AttributeObject(); Assert.Null(p.Oid); Assert.Null(p.RawData); }
internal static AsnEncodedDataCollection GetAsnEncodedDataCollection(System.Security.Cryptography.CAPI.CRYPT_ATTRIBUTE cryptAttribute) { AsnEncodedDataCollection datas = new AsnEncodedDataCollection(); Oid oid = new Oid(cryptAttribute.pszObjId); string name = oid.Value; for (uint i = 0; i < cryptAttribute.cValue; i++) { IntPtr pBlob = new IntPtr(((long) cryptAttribute.rgValue) + (i * Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB)))); Pkcs9AttributeObject asnEncodedData = new Pkcs9AttributeObject(oid, System.Security.Cryptography.CAPI.BlobToByteArray(pBlob)); Pkcs9AttributeObject obj3 = CryptoConfig.CreateFromName(name) as Pkcs9AttributeObject; if (obj3 != null) { obj3.CopyFrom(asnEncodedData); asnEncodedData = obj3; } datas.Add(asnEncodedData); } return datas; }
internal static AsnEncodedDataCollection GetAsnEncodedDataCollection (CAPI.CRYPT_ATTRIBUTE cryptAttribute) { AsnEncodedDataCollection list = new AsnEncodedDataCollection(); Oid oid = new Oid(cryptAttribute.pszObjId); string szOid = oid.Value; for (uint index = 0; index < cryptAttribute.cValue; index++) { checked { IntPtr pAttributeBlob = new IntPtr((long)cryptAttribute.rgValue + (index * Marshal.SizeOf(typeof(CAPI.CRYPTOAPI_BLOB)))); Pkcs9AttributeObject attribute = new Pkcs9AttributeObject(oid, CAPI.BlobToByteArray(pAttributeBlob)); Pkcs9AttributeObject customAttribute = CryptoConfig.CreateFromName(szOid) as Pkcs9AttributeObject; if (customAttribute != null) { customAttribute.CopyFrom(attribute); attribute = customAttribute; } list.Add(attribute); } } return list; }
private static Pkcs9ContentType CreatePkcs9ContentType(byte[] rawData) { Pkcs9ContentType pkcs9ContentType = new Pkcs9ContentType(); Pkcs9AttributeObject pkcs9AttributeObject = new Pkcs9AttributeObject(pkcs9ContentType.Oid, rawData); pkcs9ContentType.CopyFrom(pkcs9AttributeObject); return pkcs9ContentType; }
public static void Pkcs9AttributeCopyFromNullAsn() { Pkcs9AttributeObject p = new Pkcs9AttributeObject(); Assert.Throws<ArgumentNullException>(() => p.CopyFrom(null)); }
public static void Pkcs9AttributeAsnEncodedDataCtorNullOid() { AsnEncodedData a = new AsnEncodedData(new byte[3]); object ign; Assert.Throws<ArgumentNullException>(() => ign = new Pkcs9AttributeObject(a)); }
public static void TestUnprotectedAttributes1_ContentType_RoundTrip() { byte[] rawData = "06072a9fa20082f300".HexToByteArray(); Pkcs9AttributeObject pkcs9ContentType = new Pkcs9AttributeObject(Oids.ContentType, rawData); byte[] encodedMessage = CreateEcmsWithAttributes(pkcs9ContentType); VerifyUnprotectedAttributes1_ContentType(encodedMessage); }
public static void ContentTypeFromCookedData() { string contentType = "1.3.8473.23.4773.23"; byte[] encodedContentType = "06072bc21917a52517".HexToByteArray(); Pkcs9ContentType p = new Pkcs9ContentType(); Pkcs9AttributeObject pkcs9AttributeObject = new Pkcs9AttributeObject(p.Oid, encodedContentType); p.CopyFrom(pkcs9AttributeObject); string cookedData = p.ContentType.Value; Assert.Equal(contentType, cookedData); string oid = p.Oid.Value; Assert.Equal(s_OidContentType, oid); }