//
-// ContentInfo.cs - System.Security.Cryptography.Pkcs.ContentInfo
+// System.Security.Cryptography.Pkcs.ContentInfo
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-//
-
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-using System.Security.Cryptography;
+#if NET_2_0
using Mono.Security;
// constructors
public ContentInfo (byte[] content)
- : this (new Oid ("1.2.840.113549.1.7.1"), content) {}
+ : this (new Oid ("1.2.840.113549.1.7.1"), content)
+ {
+ }
public ContentInfo (Oid oid, byte[] content)
{
_content = content;
}
+ ~ContentInfo ()
+ {
+ }
+
// properties
public byte[] Content {
- get { return _content; }
+ get { return (byte[]) _content.Clone (); }
}
public Oid ContentType {
// static methods
- [MonoTODO("Incomplete OID support")]
+ [MonoTODO ("MS is stricter than us about the content structure")]
public static Oid GetContentType (byte[] encodedMessage)
{
-// FIXME: compatibility with fx 1.2.3400.0
if (encodedMessage == null)
- throw new NullReferenceException ();
-// throw new ArgumentNullException ("algorithm");
+ throw new ArgumentNullException ("algorithm");
+
try {
PKCS7.ContentInfo ci = new PKCS7.ContentInfo (encodedMessage);
switch (ci.ContentType) {
- // TODO - there are probably more - need testing
- case PKCS7.signedData:
- return new Oid (ci.ContentType);
- default:
- throw new CryptographicException ("Bad ASN1 - invalid OID");
+ case PKCS7.Oid.data:
+ case PKCS7.Oid.signedData: // see SignedCms class
+ case PKCS7.Oid.envelopedData: // see EnvelopedCms class
+ case PKCS7.Oid.digestedData:
+ case PKCS7.Oid.encryptedData:
+ return new Oid (ci.ContentType);
+ default:
+ // Note: the constructor will accept any "valid" OID (but that
+ // doesn't mean it's a valid ContentType structure - ASN.1 wise).
+ string msg = Locale.GetText ("Bad ASN1 - invalid OID '{0}'");
+ throw new CryptographicException (String.Format (msg, ci.ContentType));
}
}
catch (Exception e) {
- throw new CryptographicException ("Bad ASN1 - invalid structure", e);
+ throw new CryptographicException (Locale.GetText ("Bad ASN1 - invalid structure"), e);
}
}
}
}
+
+#endif