http://code.google.com/p/caffeine-hx/source/detail?r=658
Modified:
/trunk/ext3/chx/crypt/Aes.hx
/trunk/ext3/chx/crypt/Des.hx
/trunk/ext3/chx/crypt/XXTea.hx
/trunk/ext3/chx/hash/Md2.hx
/trunk/ext3/chx/hash/Sha1.hx
/trunk/ext3/chx/net/TcpSocket.hx
=======================================
--- /trunk/ext3/chx/crypt/Aes.hx Thu Jan 12 14:30:07 2012
+++ /trunk/ext3/chx/crypt/Aes.hx Sun Feb 12 19:59:39 2012
@@ -27,7 +27,7 @@
package chx.crypt;
-#if (neko || useOpenSSL)
+#if (neko || useNCrypt)
private typedef Keycontext = Dynamic;
#else
private typedef Keycontext = {
@@ -73,7 +73,7 @@
public function encryptBlock( block : Bytes ) : Bytes {
if(block.length != blockSize)
throw("bad block size");
- #if (neko || useOpenSSL)
+ #if (neko || useNCrypt)
var rv = Bytes.ofData(aes_encrypt_block( encKey, block.getData()));
if(blockSize != rv.length)
throw("returned buffer is " + rv.length + " bytes");
@@ -84,7 +84,7 @@
}
public function decryptBlock( block : Bytes ) : Bytes {
- #if (neko || useOpenSSL)
+ #if (neko || useNCrypt)
var rv = Bytes.ofData(aes_decrypt_block( decKey, block.getData()));
if(blockSize != rv.length)
throw("returned buffer is " + rv.length + " bytes");
@@ -106,7 +106,7 @@
**/
static function makeKey( encrypt : Bool, keylen : Int, buf :
Bytes, ?context : Keycontext ) : Keycontext
{
-#if (neko || useOpenSSL)
+#if (neko || useNCrypt)
return aes_create_key(encrypt, keylen, buf.getData());
#else
if(encrypt)
@@ -119,7 +119,7 @@
override public function encrypt(msg : String) {
var rv;
switch(mode) {
-#if (neko || useOpenSSL)
+#if (neko || useNCrypt)
case ECB:
rv = new String(naes_ecb_encrypt(untyped passphrase.__s, untyped
msg.__s, keylen));
case CBC:
@@ -141,7 +141,7 @@
override public function decrypt(msg : String) {
var rv;
switch(mode) {
-#if (neko || useOpenSSL)
+#if (neko || useNCrypt)
case ECB:
rv = new String(naes_ecb_decrypt(untyped passphrase.__s, untyped
msg.__s, keylen));
case CBC:
@@ -177,7 +177,7 @@
return buf;
}
-#if !(neko || useOpenSSL)
+#if !(neko || useNCrypt)
static var maxkc : Int = 8;
static var maxrk : Int = 14;
@@ -1360,7 +1360,7 @@
#end
-#if (neko || useOpenSSL)
+#if (neko || useNCrypt)
/*
//value pass, value msg, value key_len
private static var naes_ecb_encrypt =
chx.Lib.load("ncrypt","naes_ecb_encrypt",3);
=======================================
--- /trunk/ext3/chx/crypt/Des.hx Fri Apr 1 12:30:17 2011
+++ /trunk/ext3/chx/crypt/Des.hx Sun Feb 12 19:59:39 2012
@@ -39,12 +39,12 @@
import I32;
/**
-* DES Key. In neko and cpp, requires the openssl ndll.
+* DES Key. In neko requires the openssl ndll.
**/
class Des implements IBlockCipher
{
public var blockSize(__getBlockSize,null) : Int;
- #if (neko || cpp)
+ #if (neko || useOpenSSL)
var key:Dynamic;
#else
/*
@@ -153,7 +153,7 @@
public function new(key:Bytes) {
if(key.length < 8)
throw new chx.lang.OutsideBoundsException("Must be 8 bytes of key
data");
- #if (neko || cpp)
+ #if (neko || useOpenSSL)
this.key = des_create_key(key.sub(0,8).getData());
#else
this.key = key;
@@ -173,7 +173,7 @@
public function decryptBlock(block:Bytes):Bytes
{
- #if (neko || cpp)
+ #if (neko || useOpenSSL)
return Bytes.ofData(des_decrypt_block(key, block.getData()));
#else
var outBlock = Bytes.alloc(block.length);
@@ -184,7 +184,7 @@
public function dispose():Void
{
- #if (neko || cpp)
+ #if (neko || useOpenSSL)
des_destroy_key(key);
#else
for (i in 0...encKey.length) { encKey[i]=0; }
@@ -198,7 +198,7 @@
public function encryptBlock(block:Bytes):Bytes
{
- #if (neko || cpp)
+ #if (neko || useOpenSSL)
return Bytes.ofData(des_encrypt_block(key, block.getData()));
#else
var outBlock = Bytes.alloc(block.length);
@@ -207,7 +207,7 @@
#end
}
- #if !(neko || cpp)
+ #if !(neko || useOpenSSL)
/**
* generate an integer based working key based on our secret key and what
we
* processing we are planning to do.
@@ -410,7 +410,12 @@
}
-#if (neko || cpp)
+#if (neko || useOpenSSL)
+ public static function __init__()
+ {
+ chx.Lib.initDll("openssl");
+ }
+
private static var des_create_key =
chx.Lib.load("openssl","des_create_key",1);
private static var des_destroy_key =
chx.Lib.load("openssl","des_create_key",1);
private static var des_encrypt_block =
chx.Lib.load("openssl","des_encrypt_block",2);
=======================================
--- /trunk/ext3/chx/crypt/XXTea.hx Wed Jan 11 07:16:33 2012
+++ /trunk/ext3/chx/crypt/XXTea.hx Sun Feb 12 19:59:39 2012
@@ -30,7 +30,7 @@
import I32;
class XXTea implements IBlockCipher {
-#if neko
+#if (neko || useNCrypt)
var k : Void;
#else
var k : Array<Int>; // 16 bytes of key material
@@ -44,7 +44,7 @@
var m = BytesUtil.bytesToInt32LE(
BytesUtil.nullPad(key.sub(0,l), 16)
);
-#if neko
+#if (neko || useNCrypt)
k = xxtea_create_key(I32.mkNekoArray(m));
#else
k = I32.toNativeArray(m);
@@ -69,7 +69,7 @@
public function encryptBlock(plaintext : Bytes) : Bytes {
if (plaintext.length == 0) return BytesUtil.EMPTY;
-#if neko
+#if (neko || useNCrypt)
var v : Array<Int32> = BytesUtil.bytesToInt32LE(plaintext);
var n = v.length;
if (n == 1)
@@ -114,7 +114,7 @@
public function decryptBlock(ciphertext : Bytes) : Bytes
{
if (ciphertext.length == 0) return BytesUtil.EMPTY;
-#if neko
+#if (neko || useNCrypt)
var v = BytesUtil.bytesToInt32LE(ciphertext);
var n = v.length;
var rv = xxtea_decrypt_block(
@@ -153,7 +153,7 @@
}
-#if neko
+#if (neko || useNCrypt)
private static var xxtea_create_key =
chx.Lib.load("ncrypt","xxtea_create_key",1);
private static var xxtea_encrypt_block =
chx.Lib.load("ncrypt","xxtea_encrypt_block",3);
private static var xxtea_decrypt_block =
chx.Lib.load("ncrypt","xxtea_decrypt_block",3);
=======================================
--- /trunk/ext3/chx/hash/Md2.hx Wed Jan 11 12:21:57 2012
+++ /trunk/ext3/chx/hash/Md2.hx Sun Feb 12 19:59:39 2012
@@ -31,6 +31,14 @@
public function new() {
}
+
+ public function dispose() : Void {
+ for(i in 0...16) {
+ data[i] = 0;
+ checksum[i] = 0;
+ state[i] = 0;
+ }
+ }
public function toString() : String {
return "md2";
=======================================
--- /trunk/ext3/chx/hash/Sha1.hx Sun Jan 15 15:43:27 2012
+++ /trunk/ext3/chx/hash/Sha1.hx Sun Feb 12 19:59:39 2012
@@ -93,7 +93,7 @@
}
#if (neko || useOpenSSL)
- var _ctx : Void;
+ var _ctx : Dynamic;
public var value(default, null) : String;
/**
@@ -108,7 +108,7 @@
Add data to the sha calculation
**/
public function update(s : String) {
- sha_update(_ctx, untyped s.__s);
+ sha_update(_ctx, #if neko untyped s.__s #else s #end);
}
/**
@@ -127,7 +127,7 @@
public static function objEncode( o : Dynamic, ?binary : Bool ) : String {
var m : String;
if(Std.is(o, String))
- m = Bytes.ofData(nsha1(untyped o.__s)).toString();
+ m = Bytes.ofData(nsha1(#if neko untyped o.__s #else o #end)).toString();
else
m = Bytes.ofData(nsha1(o)).toString();
if(!binary)
=======================================
--- /trunk/ext3/chx/net/TcpSocket.hx Wed Apr 27 10:18:43 2011
+++ /trunk/ext3/chx/net/TcpSocket.hx Sun Feb 12 19:59:39 2012
@@ -107,10 +107,24 @@
#end
}
else s;
+ createIO();
+ bigEndian = true;
+
+ initListeners();
+ #if !neko
+ remote_host = {
+ host : new Host("localhost"),
+ port : 0
+ };
+ #end
+ }
+
+ function createIO() {
input = new TcpSocketInput(__handle);
output = new TcpSocketOutput(__handle);
- bigEndian = true;
-
+ }
+
+ function initListeners() {
#if flash9
__handle.addEventListener(Event.CONNECT, onSocketConnect,false,0,true);
__handle.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
onSocketConnectFail,false,0,true);
@@ -118,12 +132,6 @@
__handle.addEventListener(ProgressEvent.SOCKET_DATA,
onSocketData,false,0,true);
__handle.addEventListener(IOErrorEvent.IO_ERROR,
onSocketError,false,0,true);
#end
- #if !neko
- remote_host = {
- host : new Host("localhost"),
- port : 0
- };
- #end
}
public function accept() : Socket {
@@ -246,7 +254,7 @@
#end
}
- public function listen(connections : Int) {
+ public function listen(connections : Int) : Void {
#if (neko || cpp)
socket_listen(__handle, connections);
#elseif flash9
@@ -374,7 +382,16 @@
// STATICS
public static function select(read : Array<TcpSocket>, write :
Array<TcpSocket>, others : Array<TcpSocket>, timeout : Float) : {read:
Array<TcpSocket>,write: Array<TcpSocket>,others: Array<TcpSocket>} {
- #if (neko || cpp)
+ #if cpp
+ var neko_array = socket_select(read,write,others, timeout);
+ if (neko_array==null)
+ throw "Select error";
+ return {
+ read: neko_array[0],
+ write: neko_array[1],
+ others: neko_array[2]
+ };
+ #elseif neko
var c = untyped __dollar__hnew( 1 );
var f = function( a : Array<TcpSocket> ){
if( a == null ) return null;