Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2004-05-11 15:15:13 +0400
committerSebastien Pouliot <sebastien@ximian.com>2004-05-11 15:15:13 +0400
commit1292d8b3379ea16027b8753127652dae59bbb471 (patch)
tree8d4122f9678131eef29779e3ce8b87b14e31dc18 /mcs/class/Mono.Security
parent4a6d35661f768a3decc8631430110bd38e54e195 (diff)
2004-05-11 Sebastien Pouliot <sebastien@ximian.com>
* ASN1Convert.cs: Added better exceptions. Fixed bugs found by new unit tests. * StrongName.cs: Fixed GetBytes() when creating a new strongname. Removed unrequired :base() from a constructor. Removed debugging Console.WriteLine. svn path=/trunk/mcs/; revision=27082
Diffstat (limited to 'mcs/class/Mono.Security')
-rw-r--r--mcs/class/Mono.Security/Mono.Security/ASN1Convert.cs56
-rw-r--r--mcs/class/Mono.Security/Mono.Security/ChangeLog8
-rw-r--r--mcs/class/Mono.Security/Mono.Security/StrongName.cs14
3 files changed, 52 insertions, 26 deletions
diff --git a/mcs/class/Mono.Security/Mono.Security/ASN1Convert.cs b/mcs/class/Mono.Security/Mono.Security/ASN1Convert.cs
index f8e5269dbfd..d7050a2760c 100644
--- a/mcs/class/Mono.Security/Mono.Security/ASN1Convert.cs
+++ b/mcs/class/Mono.Security/Mono.Security/ASN1Convert.cs
@@ -42,47 +42,60 @@ namespace Mono.Security {
if (dt.Year < 2050) {
// UTCTIME
return new ASN1 (0x17, Encoding.ASCII.GetBytes (
- dt.ToString ("yyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"));
+ dt.ToUniversalTime ().ToString ("yyMMddHHmmss",
+ CultureInfo.InvariantCulture) + "Z"));
}
else {
// GENERALIZEDTIME
return new ASN1 (0x18, Encoding.ASCII.GetBytes (
- dt.ToString ("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"));
+ dt.ToUniversalTime ().ToString ("yyyyMMddHHmmss",
+ CultureInfo.InvariantCulture) + "Z"));
}
}
static public ASN1 FromInt32 (Int32 value)
{
byte[] integer = BitConverterLE.GetBytes (value);
- int x = 3;
- while (integer [x] == 0x00)
- x--;
+ Array.Reverse (integer);
+ int x = 0;
+ while ((x < integer.Length) && (integer [x] == 0x00))
+ x++;
ASN1 asn1 = new ASN1 (0x02);
-
- byte[] smallerInt = new byte [x + 1];
- int index = smallerInt.Length - 1;
- for (int i = 0; i < smallerInt.Length; i++) {
- smallerInt [index] = integer [i];
- index--;
+ switch (x) {
+ case 0:
+ asn1.Value = integer;
+ break;
+ case 4:
+ asn1.Value = new byte [0];
+ break;
+ default:
+ byte[] smallerInt = new byte [4 - x];
+ Buffer.BlockCopy (integer, x, smallerInt, 0, smallerInt.Length);
+ asn1.Value = smallerInt;
+ break;
}
- asn1.Value = smallerInt;
-
return asn1;
}
static public ASN1 FromOid (string oid)
{
+ if (oid == null)
+ throw new ArgumentNullException ("oid");
+
return new ASN1 (CryptoConfig.EncodeOID (oid));
}
static public ASN1 FromUnsignedBigInteger (byte[] big)
{
- if (big [0] == 0x00) {
- // this first byte is added so we're sure it's an unsigned integer
+ if (big == null)
+ throw new ArgumentNullException ("big");
+
+ if (big [0] != 0x00) {
+ // this first byte is added so we're sure this is an unsigned integer
// however we can't feed it into RSAParameters or DSAParameters
int length = big.Length + 1;
byte[] uinteger = new byte [length];
- Buffer.BlockCopy (big, 0, uinteger, 1, length);
+ Buffer.BlockCopy (big, 0, uinteger, 1, length - 1);
big = uinteger;
}
return new ASN1 (0x02, big);
@@ -90,8 +103,11 @@ namespace Mono.Security {
static public int ToInt32 (ASN1 asn1)
{
+ if (asn1 == null)
+ throw new ArgumentNullException ("asn1");
if (asn1.Tag != 0x02)
- throw new NotSupportedException ("Only integer can be converted");
+ throw new FormatException ("Only integer can be converted");
+
int x = 0;
for (int i=0; i < asn1.Value.Length; i++)
x = (x << 8) + asn1.Value [i];
@@ -102,6 +118,9 @@ namespace Mono.Security {
// an OID (IETF style). Based on DUMPASN1.C from Peter Gutmann.
static public string ToOid (ASN1 asn1)
{
+ if (asn1 == null)
+ throw new ArgumentNullException ("asn1");
+
byte[] aOID = asn1.Value;
StringBuilder sb = new StringBuilder ();
// Pick apart the OID
@@ -129,6 +148,9 @@ namespace Mono.Security {
static public DateTime ToDateTime (ASN1 time)
{
+ if (time == null)
+ throw new ArgumentNullException ("time");
+
string t = Encoding.ASCII.GetString (time.Value);
// to support both UTCTime and GeneralizedTime (and not so common format)
string mask = null;
diff --git a/mcs/class/Mono.Security/Mono.Security/ChangeLog b/mcs/class/Mono.Security/Mono.Security/ChangeLog
index 4dce957da9f..297a69983f3 100644
--- a/mcs/class/Mono.Security/Mono.Security/ChangeLog
+++ b/mcs/class/Mono.Security/Mono.Security/ChangeLog
@@ -1,3 +1,11 @@
+2004-05-11 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ASN1Convert.cs: Added better exceptions. Fixed bugs found by new
+ unit tests.
+ * StrongName.cs: Fixed GetBytes() when creating a new strongname.
+ Removed unrequired :base() from a constructor. Removed debugging
+ Console.WriteLine.
+
2004-05-03 Sebastien Pouliot <sebastien@ximian.com>
* ASN1.cs: Fixed NullReferenceException in xmldsig standalone tests.
diff --git a/mcs/class/Mono.Security/Mono.Security/StrongName.cs b/mcs/class/Mono.Security/Mono.Security/StrongName.cs
index b95525ba479..f1ae174209b 100644
--- a/mcs/class/Mono.Security/Mono.Security/StrongName.cs
+++ b/mcs/class/Mono.Security/Mono.Security/StrongName.cs
@@ -116,7 +116,7 @@ namespace Mono.Security {
}
}
- public StrongName (RSA rsa) : base ()
+ public StrongName (RSA rsa)
{
if (rsa == null)
throw new ArgumentNullException ("rsa");
@@ -242,7 +242,7 @@ namespace Mono.Security {
public byte[] GetBytes ()
{
- return CryptoConvert.ToCapiPrivateKeyBlob (rsa);
+ return CryptoConvert.ToCapiPrivateKeyBlob (RSA);
}
private UInt32 RVAtoPosition (UInt32 r, int sections, byte[] headers)
@@ -409,21 +409,17 @@ namespace Mono.Security {
fs.Close ();
}
if (sn.Hash == null) {
- Console.WriteLine ("hash is null");
return false;
- }
+ }
try {
AssemblyHashAlgorithm algorithm = AssemblyHashAlgorithm.SHA1;
if (tokenAlgorithm == "MD5")
algorithm = AssemblyHashAlgorithm.MD5;
- bool v = Verify (rsa, algorithm, sn.Hash, sn.Signature);
- Console.WriteLine ("returning v: " + v);
- return v;
+ return Verify (rsa, algorithm, sn.Hash, sn.Signature);
}
- catch (CryptographicException e) {
+ catch (CryptographicException) {
// no exception allowed
- Console.WriteLine ("exception: " + e);
return false;
}
}