diff options
author | Marek Safar <marek.safar@gmail.com> | 2010-09-14 18:07:57 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2010-09-14 18:07:57 +0400 |
commit | d5806dc95c134323352ac95c9923d22700e70e9f (patch) | |
tree | 18b7709cdee9858a232da97477d986edc413ab48 /asn1view | |
parent | 55e07850d58e9e073163ece68816d41eadbb1f3a (diff) |
Revert "[639072] Initialize evaluator before using it."
This reverts commit 55e07850d58e9e073163ece68816d41eadbb1f3a.
Diffstat (limited to 'asn1view')
-rw-r--r-- | asn1view/common/ASN1Decoder.cs | 306 | ||||
-rw-r--r-- | asn1view/common/PrettyPrinter.cs | 44 |
2 files changed, 175 insertions, 175 deletions
diff --git a/asn1view/common/ASN1Decoder.cs b/asn1view/common/ASN1Decoder.cs index 3d515bc7..e5d69e2e 100644 --- a/asn1view/common/ASN1Decoder.cs +++ b/asn1view/common/ASN1Decoder.cs @@ -16,166 +16,166 @@ using System.Text; namespace Mono.Security { - public class ASN1Element { - - private byte [] _data; - private int _position; - private int _valueLength; - private int _valuePosition; - private ArrayList _childs; - - public ASN1Element (byte[] buffer, int start) - { - _data = buffer; - _position = start; - _valuePosition = start + 1; - - _valueLength = _data [_valuePosition++]; - - // special case #1 : undefined length - if (_valueLength == 0x80) { - // Value.Length will have it anyway - _valueLength = -1; - } - // special case where L contains the Length of the Length + 0x80 - else if ((_valueLength & 0x80) == 0x80) { - int len = _valueLength & 0x7F; - _valueLength = 0; - for (int i = 0; i < len; i++) - _valueLength = _valueLength * 256 + _data [_valuePosition++]; - } - - if (IsConstructed && (_valueLength != 0)) { - DecodeChilds (); - if (_valueLength == -1) { - // update to the true (known) length - int childLength = 0; - if ((_childs != null) && (_childs.Count > 0)) { - foreach (ASN1Element child in _childs) { - childLength += child.TotalLength; - } - } - _valueLength = childLength; - } - } - } - - public byte Tag { - get { return _data [_position]; } - } - - public int Length { - get { return _valueLength; } - } - - public byte[] Value { - get { - if (_valueLength < 0) - return null; - byte[] value = new byte [_valueLength]; - Buffer.BlockCopy (_data, _valuePosition, value, 0, value.Length); - return value; - } - } - - public bool IsConstructed { - get { return ((_data [_position] & 0x20) == 0x20); } - } - - public bool IsUndefinedLength { - get { return (_data [_position + 1] == 0x80); } - } - - public int Count { - get { - if (_childs == null) - return 0; - return _childs.Count; - } - } - - public ASN1Element this [int index] { - get { - try { - if ((index < 0) || (index >= _childs.Count)) - return null; - return (ASN1Element)_childs [index]; - } - catch (ArgumentOutOfRangeException) { - return null; - } + public class ASN1Element {
+
+ private byte [] _data;
+ private int _position;
+ private int _valueLength;
+ private int _valuePosition;
+ private ArrayList _childs;
+
+ public ASN1Element (byte[] buffer, int start)
+ {
+ _data = buffer;
+ _position = start;
+ _valuePosition = start + 1;
+
+ _valueLength = _data [_valuePosition++];
+
+ // special case #1 : undefined length
+ if (_valueLength == 0x80) {
+ // Value.Length will have it anyway
+ _valueLength = -1;
+ }
+ // special case where L contains the Length of the Length + 0x80
+ else if ((_valueLength & 0x80) == 0x80) {
+ int len = _valueLength & 0x7F;
+ _valueLength = 0;
+ for (int i = 0; i < len; i++)
+ _valueLength = _valueLength * 256 + _data [_valuePosition++];
} +
+ if (IsConstructed && (_valueLength != 0)) {
+ DecodeChilds ();
+ if (_valueLength == -1) {
+ // update to the true (known) length
+ int childLength = 0;
+ if ((_childs != null) && (_childs.Count > 0)) {
+ foreach (ASN1Element child in _childs) {
+ childLength += child.TotalLength;
+ }
+ }
+ _valueLength = childLength;
+ }
+ }
+ }
+
+ public byte Tag {
+ get { return _data [_position]; }
+ }
+
+ public int Length {
+ get { return _valueLength; }
+ }
+
+ public byte[] Value {
+ get {
+ if (_valueLength < 0)
+ return null;
+ byte[] value = new byte [_valueLength];
+ Buffer.BlockCopy (_data, _valuePosition, value, 0, value.Length);
+ return value;
+ }
+ }
+
+ public bool IsConstructed {
+ get { return ((_data [_position] & 0x20) == 0x20); }
+ }
+
+ public bool IsUndefinedLength {
+ get { return (_data [_position + 1] == 0x80); }
+ }
+
+ public int Count {
+ get {
+ if (_childs == null)
+ return 0;
+ return _childs.Count;
+ }
+ }
+
+ public ASN1Element this [int index] {
+ get {
+ try {
+ if ((index < 0) || (index >= _childs.Count))
+ return null;
+ return (ASN1Element)_childs [index];
+ }
+ catch (ArgumentOutOfRangeException) {
+ return null;
+ }
+ }
} public int Position { get { return _position; } - } - - internal int TotalLength { - get { return _valuePosition - _position + _valueLength; } + }
+
+ internal int TotalLength {
+ get { return _valuePosition - _position + _valueLength; }
} // note: Length has a variable length ;-) public int ValuePosition { get { return _valuePosition; } - } - - private void DecodeChilds () - { - _childs = new ArrayList (); - int childpos = _valuePosition; - int end = childpos + _valueLength; - while ((_valueLength == -1) || (childpos < end)) { - ASN1Element el = new ASN1Element (_data, childpos); - _childs.Add (el); - childpos += el.TotalLength; - // exit condition for undefined length (_valueLength == -1) - if ((el.Tag == 0x00) && (el.Length == 0)) - break; - } - } - - public override string ToString () - { - StringBuilder sb = new StringBuilder (); - BuildString (sb, 0); - return sb.ToString (); - } - - internal void BuildString (StringBuilder sb, int level) - { - for (int i = 0; i < level; i++) { - sb.Append (" "); - } - if (this.Value != null) { - if (this.Count > 0) { - sb.AppendFormat ("Tag {0} Length {1} {2} {3}", - this.Tag.ToString ("X2"), - this.Length, "{", - Environment.NewLine); - - for (int j = 0; j < this.Count; j++) { - (this [j] as ASN1Element).BuildString (sb, level + 1); - } - for (int i = 0; i < level; i++) { - sb.Append (" "); - } - sb.AppendFormat ("{0} {1}", "}", Environment.NewLine); - } - else { - sb.AppendFormat ("Tag {0} Length {1} Value {2} {3}", - this.Tag.ToString ("X2"), - this.Length, - (this.Length == 0) ? String.Empty : BitConverter.ToString (this.Value), - Environment.NewLine); - } - } - else { - sb.AppendFormat ("Tag {0} Length {1} {2}", - this.Tag.ToString ("X2"), - this.IsUndefinedLength ? "Undefined" : "0", - Environment.NewLine); - } - } - } -} + }
+
+ private void DecodeChilds ()
+ {
+ _childs = new ArrayList ();
+ int childpos = _valuePosition;
+ int end = childpos + _valueLength;
+ while ((_valueLength == -1) || (childpos < end)) {
+ ASN1Element el = new ASN1Element (_data, childpos);
+ _childs.Add (el);
+ childpos += el.TotalLength;
+ // exit condition for undefined length (_valueLength == -1)
+ if ((el.Tag == 0x00) && (el.Length == 0))
+ break;
+ }
+ }
+
+ public override string ToString ()
+ {
+ StringBuilder sb = new StringBuilder ();
+ BuildString (sb, 0);
+ return sb.ToString ();
+ }
+
+ internal void BuildString (StringBuilder sb, int level)
+ {
+ for (int i = 0; i < level; i++) {
+ sb.Append (" ");
+ }
+ if (this.Value != null) {
+ if (this.Count > 0) {
+ sb.AppendFormat ("Tag {0} Length {1} {2} {3}",
+ this.Tag.ToString ("X2"),
+ this.Length, "{",
+ Environment.NewLine);
+
+ for (int j = 0; j < this.Count; j++) {
+ (this [j] as ASN1Element).BuildString (sb, level + 1);
+ }
+ for (int i = 0; i < level; i++) {
+ sb.Append (" ");
+ }
+ sb.AppendFormat ("{0} {1}", "}", Environment.NewLine);
+ }
+ else {
+ sb.AppendFormat ("Tag {0} Length {1} Value {2} {3}",
+ this.Tag.ToString ("X2"),
+ this.Length,
+ (this.Length == 0) ? String.Empty : BitConverter.ToString (this.Value),
+ Environment.NewLine);
+ }
+ }
+ else {
+ sb.AppendFormat ("Tag {0} Length {1} {2}",
+ this.Tag.ToString ("X2"),
+ this.IsUndefinedLength ? "Undefined" : "0",
+ Environment.NewLine);
+ }
+ }
+ }
+}
diff --git a/asn1view/common/PrettyPrinter.cs b/asn1view/common/PrettyPrinter.cs index 466aec11..5cdbdf40 100644 --- a/asn1view/common/PrettyPrinter.cs +++ b/asn1view/common/PrettyPrinter.cs @@ -160,8 +160,8 @@ namespace Mono.Tools { private void Indent (StringBuilder sb, int level) { - for (int i = 0; i < level; i++) { - sb.Append (_options.Indentation); + for (int i = 0; i < level; i++) {
+ sb.Append (_options.Indentation);
} } @@ -389,7 +389,7 @@ namespace Mono.Tools { } else { // TODO: Use BigInteger class to display the beast PrintBinaryData (sb, level, value, 0, value.Length); - } + }
} // 0x03 BIT STRING @@ -482,17 +482,17 @@ namespace Mono.Tools { string name = ResolveOid (oid); if (name.Length > 0) sb.AppendFormat ("{0} ", name); - +
switch (_options.OidFormat) { case OidFormat.ITU: sb.AppendFormat ("({0})", oid.Replace ('.', ' ')); break; // 0x0C UTF8 STRING case OidFormat.URN: sb.AppendFormat ("(urn:oid:{0})", oid); - break; + break;
default: sb.AppendFormat ("({0})", oid); - break; + break;
} } @@ -673,22 +673,22 @@ namespace Mono.Tools { private string DecodeOid (byte[] oid) { StringBuilder sb = new StringBuilder (); - // Pick apart the OID - byte x = (byte) (oid [0] / 40); - byte y = (byte) (oid [0] % 40); - if (x > 2) { - // Handle special case for large y if x = 2 - y += (byte) ((x - 2) * 40); - x = 2; - } - sb.AppendFormat ("{0}.{1}", x, y); - ulong val = 0; - for (x = 1; x < oid.Length; x++) { - val = ((val << 7) | ((byte) (oid [x] & 0x7F))); - if ( !((oid [x] & 0x80) == 0x80)) { - sb.AppendFormat (".{0}", val); - val = 0; - } + // Pick apart the OID
+ byte x = (byte) (oid [0] / 40);
+ byte y = (byte) (oid [0] % 40);
+ if (x > 2) {
+ // Handle special case for large y if x = 2
+ y += (byte) ((x - 2) * 40);
+ x = 2;
+ }
+ sb.AppendFormat ("{0}.{1}", x, y);
+ ulong val = 0;
+ for (x = 1; x < oid.Length; x++) {
+ val = ((val << 7) | ((byte) (oid [x] & 0x7F)));
+ if ( !((oid [x] & 0x80) == 0x80)) {
+ sb.AppendFormat (".{0}", val);
+ val = 0;
+ }
} return sb.ToString (); } |