Files
sdk/lib/crypto/crypto.dart
T
johnniwinther@google.com c6d70857e4 Several new features and improvements for dartdoc.
* Dartdoc now works on multiple libraries and entrypoints.
* A dartdoc/dartdoc.bat script is generated into dart-sdk/bin
* The API libraries recognized by dart2js using the 'dart:' prefix
  have been updated to use the 'dart:*' name in their library tags.
  This makes the libraries show up with the correct prefix in the API docs.
* The processed libraries can be selected or limited, API
  libraries are not processed by default, and links to api.dartlang.org
  can be generated for API libraries.

  Because of the changed library tags on API libraries, the generated
  links don't current match the addresses on api.dartlang.org.
  For instance, the docs for Object is currently located in
  api.dartlang.org/core/Object.html, but with the new library
  tag 'dart:core', the address will be api.dartlang.org/dart_core/Object.html.
  The links will thus not work until api.dartlang.org have been updated with
  this patch.
* Code and pre blocks use overflow-x:auto to support wide lines.

BUG=2656,2686,3533,4029,4145,3555

Review URL: https://chromiumcodereview.appspot.com//10809035

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9843 260f80e4-7a28-3924-810f-c04153c831b5
2012-07-24 09:16:33 +00:00

130 lines
2.9 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#library('dart:crypto');
#source('crypto_utils.dart');
#source('hash_utils.dart');
#source('hmac.dart');
#source('md5.dart');
#source('sha1.dart');
#source('sha256.dart');
/**
* Interface for cryptographic hash functions.
*
* The [update] method is used to add data to the hash. The [digest] method
* is used to extract the message digest.
*
* Once the [digest] method has been called no more data can be added using the
* [update] method. If [update] is called after the first call to [digest] a
* HashException is thrown.
*
* If multiple instances of a given Hash is needed the [newInstance]
* method can provide a new instance.
*/
interface Hash {
/**
* Add a list of bytes to the hash computation.
*/
Hash update(List<int> data);
/**
* Finish the hash computation and extract the message digest as
* a list of bytes.
*/
List<int> digest();
/**
* Returns a new instance of this hash function.
*/
Hash newInstance();
/**
* Block size of the hash in bytes.
*/
int get blockSize();
}
/**
* SHA1 hash function implementation.
*/
interface SHA1 extends Hash default _SHA1 {
SHA1();
}
/**
* SHA256 hash function implementation.
*/
interface SHA256 extends Hash default _SHA256 {
SHA256();
}
/**
* MD5 hash function implementation.
*
* WARNING: MD5 has known collisions and should only be used when
* required for backwards compatibility.
*/
interface MD5 extends Hash default _MD5 {
MD5();
}
/**
* Hash-based Message Authentication Code support.
*
* The [update] method is used to add data to the message. The [digest] method
* is used to extract the message authentication code.
*/
interface HMAC default _HMAC {
/**
* Create an [HMAC] object from a [Hash] and a key.
*/
HMAC(Hash hash, List<int> key);
/**
* Add a list of bytes to the message.
*/
HMAC update(List<int> data);
/**
* Perform the actual computation and extract the message digest
* as a list of bytes.
*/
List<int> digest();
}
/**
* Utility methods for working with message digests.
*/
class CryptoUtils {
/**
* Convert a list of bytes (for example a message digest) into a hex
* string.
*/
static String bytesToHex(List<int> bytes) {
return _CryptoUtils.bytesToHex(bytes);
}
/**
* Converts a list of bytes (for example a message digest) into a
* base64 encoded string optionally broken up in to lines of
* [lineLength] chars separated by '\r\n'.
*/
static String bytesToBase64(List<int> bytes, [int lineLength]) {
return _CryptoUtils.bytesToBase64(bytes, lineLength);
}
}
/**
* HashExceptions are thrown on invalid use of a Hash
* object.
*/
class HashException {
HashException(String this.message);
toString() => "HashException: $message";
String message;
}