~ubuntu-branches/ubuntu/vivid/emscripten/vivid-proposed

« back to all changes in this revision

Viewing changes to third_party/websockify/include/web-socket-js/src/flash-src/third-party/com/hurlant/crypto/symmetric/SimpleIVMode.as

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * SimpleIVMode
 
3
 * 
 
4
 * A convenience class that automatically places the IV
 
5
 * at the beginning of the encrypted stream, so it doesn't have to
 
6
 * be handled explicitely.
 
7
 * Copyright (c) 2007 Henri Torgemane
 
8
 * 
 
9
 * See LICENSE.txt for full license information.
 
10
 */
 
11
package com.hurlant.crypto.symmetric
 
12
{
 
13
        import flash.utils.ByteArray;
 
14
        import com.hurlant.util.Memory;
 
15
        
 
16
        public class SimpleIVMode implements IMode, ICipher
 
17
        {
 
18
                protected var mode:IVMode;
 
19
                protected var cipher:ICipher;
 
20
                
 
21
                public function SimpleIVMode(mode:IVMode) {
 
22
                        this.mode = mode;
 
23
                        cipher = mode as ICipher;
 
24
                }
 
25
                
 
26
                public function getBlockSize():uint {
 
27
                        return mode.getBlockSize();
 
28
                }
 
29
                
 
30
                public function dispose():void {
 
31
                        mode.dispose();
 
32
                        mode = null;
 
33
                        cipher = null;
 
34
                        Memory.gc();
 
35
                }
 
36
                
 
37
                public function encrypt(src:ByteArray):void {
 
38
                        cipher.encrypt(src);
 
39
                        var tmp:ByteArray = new ByteArray;
 
40
                        tmp.writeBytes(mode.IV);
 
41
                        tmp.writeBytes(src);
 
42
                        src.position=0;
 
43
                        src.writeBytes(tmp);
 
44
                }
 
45
                
 
46
                public function decrypt(src:ByteArray):void {
 
47
                        var tmp:ByteArray = new ByteArray;
 
48
                        tmp.writeBytes(src, 0, getBlockSize());
 
49
                        mode.IV = tmp;
 
50
                        tmp = new ByteArray;
 
51
                        tmp.writeBytes(src, getBlockSize());
 
52
                        cipher.decrypt(tmp);
 
53
                        src.length=0;
 
54
                        src.writeBytes(tmp);
 
55
                }
 
56
                public function toString():String {
 
57
                        return "simple-"+cipher.toString();
 
58
                }
 
59
        }
 
60
}
 
 
b'\\ No newline at end of file'