PageRenderTime 177ms CodeModel.GetById 161ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/flash-src/third-party/com/hurlant/util/der/Sequence.as

http://github.com/gimite/web-socket-js
ActionScript | 90 lines | 70 code | 10 blank | 10 comment | 15 complexity | 1618778ac0053aa0566b96dd1a40639d MD5 | raw file
 1/**
 2 * Sequence
 3 * 
 4 * An ASN1 type for a Sequence, implemented as an Array
 5 * Copyright (c) 2007 Henri Torgemane
 6 * 
 7 * See LICENSE.txt for full license information.
 8 */
 9package com.hurlant.util.der
10{
11	import flash.utils.ByteArray;
12	
13	public dynamic class Sequence extends Array implements IAsn1Type
14	{
15		protected var type:uint;
16		protected var len:uint;
17		
18		public function Sequence(type:uint = 0x30, length:uint = 0x00) {
19			this.type = type;
20			this.len = length;
21		}
22		
23		public function getLength():uint
24		{
25			return len;
26		}
27		
28		public function getType():uint
29		{
30			return type;
31		}
32
33		public function toDER():ByteArray {
34			var tmp:ByteArray = new ByteArray;
35			for (var i:int=0;i<length;i++) {
36				var e:IAsn1Type = this[i];
37				if (e == null) { // XXX Arguably, I could have a der.Null class instead
38					tmp.writeByte(0x05);
39					tmp.writeByte(0x00);
40				} else {
41					tmp.writeBytes(e.toDER());
42				}
43			}
44			return DER.wrapDER(type, tmp);
45		}
46		
47		public function toString():String {
48			var s:String = DER.indent;
49			DER.indent += "    ";
50			var t:String = "";
51			for (var i:int=0;i<length;i++) {
52				if (this[i]==null) continue;
53				var found:Boolean = false;
54				for (var key:String in this) {
55					if ( (i.toString()!=key) && this[i]==this[key]) {
56						t += key+": "+this[i]+"\n";
57						found = true;
58						break;
59					}
60				}
61				if (!found) t+=this[i]+"\n";
62			}
63//			var t:String = join("\n");
64			DER.indent= s;
65			return DER.indent+"Sequence["+type+"]["+len+"][\n"+t+"\n"+s+"]";
66		}
67		
68		/////////
69		
70		public function findAttributeValue(oid:String):IAsn1Type {
71			for each (var set:* in this) {
72				if (set is Set) {
73					var child:* = set[0];
74					if (child is Sequence) {
75						var tmp:* = child[0];
76						if (tmp is ObjectIdentifier) {
77							var id:ObjectIdentifier = tmp as ObjectIdentifier;
78							if (id.toString()==oid) {
79								return child[1] as IAsn1Type;
80							}
81						}
82					}
83				}
84			}
85			return null;
86		}
87		
88		
89	}
90}