OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #library('crypto'); |
| 6 #import('node.dart'); |
| 7 |
| 8 // module crypto |
| 9 |
| 10 class crypto native "require('crypto')" { |
| 11 static Credentials createCredentials([Map<String,Object> details]) native; |
| 12 static Hash createHash(String algorithm) native; |
| 13 static Hmac createHmac(String algorithm, String key) native; |
| 14 static Cipher createCipher(String algorithm, String password) native; |
| 15 static Cipher createCipheriv(String algorithm, String key, String iv) native; |
| 16 static Decipher createDecipher(String algorithm, String password) native; |
| 17 static Decipher createDecipheriv(String algorithm, String key, String iv) nati
ve; |
| 18 static Signer createSign(String algorithm) native; |
| 19 static Verifier createVerify(String algorithm) native; |
| 20 static DiffieHellman createDiffieHellman(int prime_length) native; |
| 21 static DiffieHellman createDiffieHellmanFromPrime(String prime, [String encodi
ng]) |
| 22 native "return this.createDiffieHellman(prime, encoding);"; |
| 23 static void pbkdf2(String password, String salt, int iterations, int keylen, |
| 24 void callback(Error err, String derivedKey)) native; |
| 25 static SlowBuffer randomBytes(size, |
| 26 [void callback(Error error, SlowBuffer sb)]) native; |
| 27 } |
| 28 |
| 29 /** |
| 30 * This is a heap-based buffer. It is an implementation detail of node.js, |
| 31 * but unfortunately it is exposed by crypto.randomBytes. |
| 32 * |
| 33 */ |
| 34 class SlowBuffer implements Buffer native '*SlowBuffer' { |
| 35 int write(String string, int offset, int length, [String encoding='utf8']) |
| 36 native; |
| 37 String toString(String encoding, int start, int end) native; |
| 38 |
| 39 // List<int> protocol |
| 40 int operator[](int index) native; |
| 41 int operator[]=(int index, int value) native; |
| 42 |
| 43 void _throwUnsupported() { |
| 44 throw new UnsupportedOperationException('not extendable'); |
| 45 } |
| 46 void add(int value) => _throwUnsupported(); |
| 47 void addAll(Collection<int> collection) => _throwUnsupported(); |
| 48 void addLast(int value) => _throwUnsupported(); |
| 49 void clear() => _throwUnsupported(); |
| 50 List<int> getRange(int start, int length) { |
| 51 _getRangeCheck(this.length, start, length); |
| 52 Buffer b = new Buffer(length); |
| 53 this.copy(b, 0, start, start + length); |
| 54 return b; |
| 55 } |
| 56 int indexOf(int element, [int start]) |
| 57 => _indexOf(this, element, start); |
| 58 void insertRange(int start, int length, [int initialValue]) |
| 59 => _throwUnsupported(); |
| 60 int last() |
| 61 => _last(this); |
| 62 int lastIndexOf(int element, [int start]) |
| 63 => _lastIndexOf(this, element, start); |
| 64 int removeLast() {_throwUnsupported(); return 0; } |
| 65 void removeRange(int start, int length) => _throwUnsupported(); |
| 66 void setRange(int start, int length, List<int> from, [int startFrom]) |
| 67 => _throwUnsupported(); |
| 68 void sort(int compare(int a, int b)) |
| 69 => DualPivotQuicksort.sort(this, compare); |
| 70 |
| 71 // Collection<int> members: |
| 72 void forEach(void f(int element)) => _forEach(this, f); |
| 73 Buffer filter(bool f(int element)) |
| 74 => _filter(this, f, (length) => new Buffer(length)); |
| 75 bool every(bool f(int element)) => _every(this, f); |
| 76 bool some(bool f(int element)) => _some(this, f); |
| 77 bool isEmpty() => _isEmpty(this); |
| 78 |
| 79 // Iterable<int> members: |
| 80 Iterator<int> iterator() => new ListIterator(this); |
| 81 |
| 82 static bool isBuffer(obj) native; |
| 83 static int byteLength(String string, [String encoding='utf8']) native; |
| 84 final length; |
| 85 void copy(Buffer targetBuffer, int targetStart, int sourceStart, int sourceEnd |
| 86 ) native; |
| 87 Buffer slice(int start, int end) native; |
| 88 |
| 89 int readUInt8(int offset, [bool noAssert=false]) native; |
| 90 int readUInt16LE(int offset, [bool noAssert=false]) native; |
| 91 int readUInt16BE(int offset, [bool noAssert=false]) native; |
| 92 int readUInt32LE(int offset, [bool noAssert=false]) native; |
| 93 int readUInt32BE(int offset, [bool noAssert=false]) native; |
| 94 |
| 95 int readInt8(int offset, [bool noAssert=false]) native; |
| 96 int readInt16LE(int offset, [bool noAssert=false]) native; |
| 97 int readInt16BE(int offset, [bool noAssert=false]) native; |
| 98 int readInt32LE(int offset, [bool noAssert=false]) native; |
| 99 int readInt32BE(int offset, [bool noAssert=false]) native; |
| 100 |
| 101 double readFloatLE(int offset, [bool noAssert=false]) native; |
| 102 double readFloatBE(int offset, [bool noAssert=false]) native; |
| 103 double readDoubleLE(int offset, [bool noAssert=false]) native; |
| 104 double readDoubleBE(int offset, [bool noAssert=false]) native; |
| 105 |
| 106 void writeUInt8(int value, int offset, [bool noAssert=false]) native; |
| 107 void writeUInt16LE(int value, int offset, [bool noAssert=false]) native; |
| 108 void writeUInt16BE(int value, int offset, [bool noAssert=false]) native; |
| 109 void writeUInt32LE(int value, int offset, [bool noAssert=false]) native; |
| 110 void writeUInt32BE(int value, int offset, [bool noAssert=false]) native; |
| 111 |
| 112 void writeInt8(int value, int offset, [bool noAssert=false]) native; |
| 113 void writeInt16LE(int value, int offset, [bool noAssert=false]) native; |
| 114 void writeInt16BE(int value, int offset, [bool noAssert=false]) native; |
| 115 void writeInt32LE(int value, int offset, [bool noAssert=false]) native; |
| 116 void writeInt32BE(int value, int offset, [bool noAssert=false]) native; |
| 117 |
| 118 void writeFloatLE(double value, int offset, [bool noAssert=false]) native; |
| 119 void writeFloatBE(double value, int offset, [bool noAssert=false]) native; |
| 120 void writeDoubleLE(double value, int offset, [bool noAssert=false]) native; |
| 121 void writeDoubleBE(double value, int offset, [bool noAssert=false]) native; |
| 122 |
| 123 // end defaults to buffer.length |
| 124 void fill(int value, int offset, int end) native; |
| 125 } |
| 126 |
| 127 class Credentials native "require('crypto').Credentials" { |
| 128 // No public protocol |
| 129 } |
| 130 |
| 131 class Hash native "require('crypto').Hash" { |
| 132 void update(String data) native; |
| 133 void updateBuffer(Buffer buffer) native "this.update(buffer);"; |
| 134 String digest([String encoding]) native; |
| 135 } |
| 136 |
| 137 class Hmac native "require('crypto').Hmac" { |
| 138 void update(var data) native; |
| 139 void updateBuffer(Buffer buffer) native "this.update(buffer);"; |
| 140 String digest([String encoding]) native; |
| 141 } |
| 142 |
| 143 class Cipher native "require('crypto').Cipher" { |
| 144 String update(String data, [String input_encoding, String output_encoding]) na
tive; |
| 145 String finalData([String output_encoding]) |
| 146 native "return this.final(output_encoding);"; |
| 147 } |
| 148 |
| 149 class Decipher native "require('crypto').Decipher" { |
| 150 String update(String data, [String input_encoding, String output_encoding]) na
tive; |
| 151 String finalData([String output_encoding]) |
| 152 native "return this.final(output_encoding);"; |
| 153 } |
| 154 |
| 155 class Signer native "require('crypto').Signer" { |
| 156 void update(String data) native; |
| 157 String sign(String private_key, [String output_format]) native; |
| 158 } |
| 159 |
| 160 class Verifier native "require('crypto').Verifier" { |
| 161 void update(String data) native; |
| 162 bool verify(String object, String signature, [String signature_format]) native
; |
| 163 } |
| 164 |
| 165 class DiffieHellman native "require('crypto').DiffieHellman" { |
| 166 String generateKeys([String encoding]) native; |
| 167 String computeSecret(String other_public_key, |
| 168 [String input_encoding, String output_encoding]) native; |
| 169 String getPrime([String encoding]) native; |
| 170 String getGenerator([String encoding]) native; |
| 171 String getPublicKey([String encoding]) native; |
| 172 String getPrivateKey([String encoding]) native; |
| 173 String setPublicKey(String public_key, [String encoding]) native; |
| 174 String setPrivateKey(String private_key, [String encoding]) native; |
| 175 } |
OLD | NEW |