Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / lib / vendor / web-socket-js / flash-src / com / hurlant / crypto / tls / BulkCiphers.as
1 /**
2  * BulkCiphers
3  * 
4  * An enumeration of bulk ciphers available for TLS, along with their properties,
5  * with a few convenience methods to go with it.
6  * Copyright (c) 2007 Henri Torgemane
7  * 
8  * See LICENSE.txt for full license information.
9  */
10 package com.hurlant.crypto.tls {
11         import com.hurlant.crypto.Crypto;
12         import flash.utils.ByteArray;
13         import com.hurlant.crypto.symmetric.ICipher;
14         import com.hurlant.crypto.symmetric.TLSPad;
15         import com.hurlant.crypto.symmetric.SSLPad;
16         
17         public class BulkCiphers {
18                 public static const STREAM_CIPHER:uint = 0;
19                 public static const BLOCK_CIPHER:uint = 1;
20
21                 public static const NULL:uint = 0;
22                 public static const RC4_40:uint = 1;
23                 public static const RC4_128:uint = 2
24                 public static const RC2_CBC_40:uint = 3; // XXX I don't have that one.
25                 public static const DES_CBC:uint = 4;
26                 public static const DES3_EDE_CBC:uint = 5;
27                 public static const DES40_CBC:uint = 6;
28                 public static const IDEA_CBC:uint = 7; // XXX I don't have that one.
29                 public static const AES_128:uint = 8;
30                 public static const AES_256:uint = 9;
31                 
32                 private static const algos:Array =
33                 ['', 'rc4', 'rc4', '', 'des-cbc', '3des-cbc', 'des-cbc', '', 'aes', 'aes'];
34                 
35                 private static var _props:Array;
36                 
37                 init();
38                 private static function init():void {
39                         _props = [];
40                         _props[NULL]                    = new BulkCiphers(STREAM_CIPHER,  0,  0,   0,  0,  0);
41                         _props[RC4_40]                  = new BulkCiphers(STREAM_CIPHER,  5, 16,  40,  0,  0);
42                         _props[RC4_128]                 = new BulkCiphers(STREAM_CIPHER, 16, 16, 128,  0,  0);
43                         _props[RC2_CBC_40]              = new BulkCiphers( BLOCK_CIPHER,  5, 16,  40,  8,  8);
44                         _props[DES_CBC]                 = new BulkCiphers( BLOCK_CIPHER,  8,  8,  56,  8,  8);
45                         _props[DES3_EDE_CBC]    = new BulkCiphers( BLOCK_CIPHER, 24, 24, 168,  8,  8);
46                         _props[DES40_CBC]               = new BulkCiphers( BLOCK_CIPHER,  5,  8,  40,  8,  8);
47                         _props[IDEA_CBC]                = new BulkCiphers( BLOCK_CIPHER, 16, 16, 128,  8,  8);
48                         _props[AES_128]                 = new BulkCiphers( BLOCK_CIPHER, 16, 16, 128, 16, 16);
49                         _props[AES_256]                 = new BulkCiphers( BLOCK_CIPHER, 32, 32, 256, 16, 16);
50                 }
51         
52                 private static function getProp(cipher:uint):BulkCiphers {
53                         var p:BulkCiphers = _props[cipher];
54                         if (p==null) {
55                                 throw new Error("Unknown bulk cipher "+cipher.toString(16));
56                         }
57                         return p;
58                 }
59                 public static function getType(cipher:uint):uint {
60                         return getProp(cipher).type;
61                 }
62                 public static function getKeyBytes(cipher:uint):uint {
63                         return getProp(cipher).keyBytes;
64                 }
65                 public static function getExpandedKeyBytes(cipher:uint):uint {
66                         return getProp(cipher).expandedKeyBytes;
67                 }
68                 public static function getEffectiveKeyBits(cipher:uint):uint {
69                         return getProp(cipher).effectiveKeyBits;
70                 }
71                 public static function getIVSize(cipher:uint):uint {
72                         return getProp(cipher).IVSize;
73                 }
74                 public static function getBlockSize(cipher:uint):uint {
75                         return getProp(cipher).blockSize;
76                 }
77                 public static function getCipher(cipher:uint, key:ByteArray, proto:uint):ICipher {
78                         if (proto == TLSSecurityParameters.PROTOCOL_VERSION) {
79                                 return Crypto.getCipher(algos[cipher], key, new TLSPad);
80                         } else {
81                                 return Crypto.getCipher(algos[cipher], key, new SSLPad);
82                         }
83                 }
84
85         
86                 private var type:uint;
87                 private var keyBytes:uint;
88                 private var expandedKeyBytes:uint;
89                 private var effectiveKeyBits:uint;
90                 private var IVSize:uint;
91                 private var blockSize:uint;
92                 
93                 public function BulkCiphers(t:uint, kb:uint, ekb:uint, fkb:uint, ivs:uint, bs:uint) {
94                         type = t;
95                         keyBytes = kb;
96                         expandedKeyBytes = ekb;
97                         effectiveKeyBits = fkb;
98                         IVSize = ivs;
99                         blockSize = bs;
100                 }
101         }
102 }