Remove deprecated APIs.
R=rnystrom@google.com
Review URL: https://codereview.chromium.org//1819293003 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d97adc..64fc6d5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 1.0.0
+
+* All APIs that were deprecated in 0.9.2 have been removed. No new APIs have
+ been added. Packages that would use 1.0.0 as a lower bound should use 0.9.2
+ instead—for example, `crypto: ">=0.9.2 <2.0.0"`.
+
## 0.9.2
* `Hash`, `MD5`, `SHA1`, and `SHA256` now implement `Converter`. They convert
diff --git a/lib/crypto.dart b/lib/crypto.dart
index b4e7ab8..990349a 100644
--- a/lib/crypto.dart
+++ b/lib/crypto.dart
@@ -2,10 +2,6 @@
// 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.
-export 'src/base64.dart';
-export 'src/base64/decoder.dart';
-export 'src/base64/encoder.dart';
-export 'src/crypto_utils.dart';
export 'src/digest.dart';
export 'src/hash.dart';
export 'src/hmac.dart';
diff --git a/lib/src/base64.dart b/lib/src/base64.dart
deleted file mode 100644
index 91d672b..0000000
--- a/lib/src/base64.dart
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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.
-
-import 'dart:convert';
-
-import 'base64/decoder.dart';
-import 'base64/encoder.dart';
-
-/// This is deprecated.
-///
-/// Use the `BASE64` constant in `dart:convert` instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-const Base64Codec BASE64 = const Base64Codec();
-
-/// This is deprecated.
-///
-/// Use the `Base64Codec` class in `dart:convert` instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class Base64Codec extends Codec<List<int>, String> {
- final bool _urlSafe;
- final bool _addLineSeparator;
- final bool _encodePaddingCharacter;
-
- /// Creates a new [Base64Codec].
- ///
- /// The default [BASE64] codec will be good enough for most cases. A new codec
- /// only needs to be instantiated when you want to do multiple conversions
- /// with the same configuration.
- ///
- /// If [urlSafe] is `true`, a URL-safe alphabet will be used when encoding.
- /// Specifically, the characters `-` and `_` will be used instead of `+` and
- /// `/`.
- ///
- /// If [addLineSeparator] is `true`, `\r\n` line separators will be added
- /// every 76 characters when encoding.
- ///
- /// If [encodePaddingCharacter] is `true`, the padding character `=` will be
- /// written as `%3D` when encoding.
- const Base64Codec(
- {bool urlSafe: false,
- bool addLineSeparator: false,
- bool encodePaddingCharacter: false})
- : _urlSafe = urlSafe,
- _addLineSeparator = addLineSeparator,
- _encodePaddingCharacter = encodePaddingCharacter;
-
- String get name => "base64";
-
- /// Encodes [bytes] into a Base64 string.
- ///
- /// If [urlSafe] is `true`, a URL-safe alphabet will be used when encoding.
- /// Specifically, the characters `-` and `_` will be used instead of `+` and
- /// `/`.
- ///
- /// If [addLineSeparator] is `true`, `\r\n` line separators will be added
- /// every 76 characters when encoding.
- ///
- /// If [encodePaddingCharacter] is `true`, the padding character `=` will be
- /// written as `%3D` when encoding.
- ///
- /// Any flags passed to this method take precedence over the flags passed to
- /// the codec itself.
- String encode(List<int> bytes,
- {bool urlSafe, bool addLineSeparator, bool encodePaddingCharacter}) {
- if (urlSafe == null) urlSafe = _urlSafe;
- if (addLineSeparator == null) addLineSeparator = _addLineSeparator;
- if (encodePaddingCharacter == null) {
- encodePaddingCharacter = _encodePaddingCharacter;
- }
-
- return new Base64Encoder(
- urlSafe: urlSafe,
- addLineSeparator: addLineSeparator,
- encodePaddingCharacter: encodePaddingCharacter).convert(bytes);
- }
-
- Base64Encoder get encoder => new Base64Encoder(
- urlSafe: _urlSafe,
- addLineSeparator: _addLineSeparator,
- encodePaddingCharacter: _encodePaddingCharacter);
-
- Base64Decoder get decoder => const Base64Decoder();
-}
diff --git a/lib/src/base64/decoder.dart b/lib/src/base64/decoder.dart
deleted file mode 100644
index 8f22a99..0000000
--- a/lib/src/base64/decoder.dart
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (c) 2015, 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.
-
-import 'dart:convert';
-import 'dart:typed_data';
-
-import 'package:charcode/ascii.dart';
-
-import 'decoder_sink.dart';
-
-/// A mapping from ASCII character codes to their corresponding Base64 values.
-///
-/// Characters with a value of `null` can't be decoded directly. This includes
-/// special values like CR, LF, `=`, and `%`.
-const _decodeTable = const [
- null, null, null, null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, null, null, null, null, null, null, null, null, null,
- null, null, null, null, 62, null, 62, null, 63, 52, 53, 54, 55, 56, 57, 58,
- 59, 60, 61, null, null, null, null, null, null, null, 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, null,
- null, null, null, 63, null, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
- 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
-];
-
-/// This is deprecated.
-///
-/// Use the `Base64Decoder` class in `dart:convert` instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class Base64Decoder extends Converter<String, List<int>> {
- const Base64Decoder();
-
- List<int> convert(String input) {
- if (input.length == 0) return new Uint8List(0);
-
- // The length of the actual data sections in the input (not CRLFs).
- var dataLength = 0;
-
- // Count the data, and fail for invalid characters.
- for (var i = 0; i < input.length; i++) {
- var codeUnit = input.codeUnitAt(i);
-
- if (codeUnit == $cr || codeUnit == $lf) continue;
-
- if (codeUnit == $percent &&
- i < input.length - 2 &&
- input.codeUnitAt(i + 1) == $3 &&
- input.codeUnitAt(i + 2) == $D) {
- dataLength++;
- i += 2;
- continue;
- }
-
- if (codeUnit != $equal &&
- (codeUnit >= _decodeTable.length || _decodeTable[codeUnit] == null)) {
- throw new FormatException('Invalid character', input, i);
- }
-
- dataLength++;
- }
-
- if (dataLength % 4 != 0) {
- throw new FormatException(
- 'Base64 input must encode a multiple of 4 bytes.',
- input,
- dataLength);
- }
-
- // Count the trailing pad characters.
- var padLength = 0;
- for (var i = input.length - 1; i >= 0; i--) {
- var codeUnit = input.codeUnitAt(i);
- if (codeUnit == $D &&
- i >= 2 &&
- input.codeUnitAt(i - 2) == $percent &&
- input.codeUnitAt(i - 1) == $3) {
- padLength++;
- i -= 2;
- } else if (codeUnit == $equal) {
- padLength++;
- } else if (codeUnit != $cr && codeUnit != $lf) {
- break;
- }
- }
- var outputLength = ((dataLength * 6) >> 3) - padLength;
- var out = new Uint8List(outputLength);
-
- var inputIndex = 0;
- var outputIndex = 0;
- while (outputIndex < outputLength) {
- // Accumulate four 6-bit Base64 characters into a 32-bit chunk.
- var chunk = 0;
- for (var i = 0; i < 4; i++) {
- var codeUnit = input.codeUnitAt(inputIndex++);
-
- if (codeUnit == $equal || codeUnit == $percent) {
- // We've reached the end of the source. Pad out the rest of the chunk
- // with zeroes.
- chunk <<= (4 - i) * 6;
- break;
- }
-
- if (codeUnit == $cr || codeUnit == $lf) {
- i--;
- } else {
- chunk = (chunk << 6) | _decodeTable[codeUnit];
- }
- }
-
- // Emit 8-bit pieces of the chunk to the output buffer.
- out[outputIndex++] = chunk >> 16;
- if (outputIndex >= outputLength) break;
-
- out[outputIndex++] = (chunk >> 8) & 0xFF;
- if (outputIndex >= outputLength) break;
-
- out[outputIndex++] = chunk & 0xFF;
- }
-
- return out;
- }
-
- Base64DecoderSink startChunkedConversion(Sink<List<int>> sink) {
- if (sink is! ByteConversionSink) sink = new ByteConversionSink.from(sink);
- return new Base64DecoderSink(sink);
- }
-}
diff --git a/lib/src/base64/decoder_sink.dart b/lib/src/base64/decoder_sink.dart
deleted file mode 100644
index 0a09a82..0000000
--- a/lib/src/base64/decoder_sink.dart
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (c) 2015, 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.
-
-import 'dart:convert';
-
-import 'decoder.dart';
-
-/// This is deprecated.
-///
-/// Use the `Base64Decoder` class in `dart:convert` instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class Base64DecoderSink extends ChunkedConversionSink<String> {
- /// The encoder used to decode each chunk.
- final Base64Decoder _decoder = new Base64Decoder();
-
- /// The underlying sink to which to emit the decoded strings.
- final ChunkedConversionSink<List<int>> _outSink;
-
- /// The as-yet-unconverted text.
- ///
- /// This is used to handle text stopping partway through a four-character
- /// 32-bit chunk.
- String _unconverted = "";
-
- Base64DecoderSink(this._outSink);
-
- void add(String chunk) {
- if (chunk.isEmpty) return;
- if (_unconverted.isNotEmpty) chunk = _unconverted + chunk;
- chunk = chunk.replaceAll("%3D", "=");
-
- // The decodable length is the length of the initial substring comprising
- // full four-character 32-bit chunks. Any leftovers are handled when [add]
- // or [close] are next called.
- var decodableLength = chunk.length;
- if (chunk.length > 3 && chunk.contains("%", chunk.length - 2)) {
- decodableLength = chunk.lastIndexOf("%");
- }
- decodableLength -= decodableLength % 4;
-
- _unconverted = chunk.substring(decodableLength);
- if (decodableLength > 0) {
- _outSink.add(_decoder.convert(chunk.substring(0, decodableLength)));
- }
- }
-
- void close() {
- if (_unconverted.isNotEmpty) _outSink.add(_decoder.convert(_unconverted));
- _outSink.close();
- }
-}
diff --git a/lib/src/base64/encoder.dart b/lib/src/base64/encoder.dart
deleted file mode 100644
index bdbf6d8..0000000
--- a/lib/src/base64/encoder.dart
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright (c) 2015, 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.
-
-import 'dart:convert';
-
-import 'package:charcode/ascii.dart';
-
-import 'encoder_sink.dart';
-
-/// A String representing a mapping from numbers between 0 and 63, inclusive, to
-/// their corresponding encoded character.
-///
-/// This is the table for URL-safe encodings.
-const _encodeTableUrlSafe =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-
-/// A String representing a mapping from numbers between 0 and 63, inclusive, to
-/// their corresponding encoded character.
-///
-/// This is the table for URL-unsafe encodings.
-const _encodeTable =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-/// The line length for Base64 strings with line separators.
-const _lineLength = 76;
-
-/// This is deprecated.
-///
-/// Use the `Base64Encoder` class in `dart:convert` instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class Base64Encoder extends Converter<List<int>, String> {
- /// Whether this encoder generates URL-safe strings.
- final bool _urlSafe;
-
- /// Whether this encoder adds line breaks to the output.
- final bool _addLineSeparator;
-
- /// The sequence of bytes to use as a padding character.
- final List<int> _pad;
-
- /// Creates a new [Base64Encoder].
- ///
- /// The default [BASE64.encoder] will be good enough for most cases. A new
- /// codec only needs to be instantiated when you want to do multiple
- /// conversions with the same configuration.
- ///
- /// If [urlSafe] is `true`, a URL-safe alphabet will be used. Specifically,
- /// the characters `-` and `_` will be used instead of `+` and `/`.
- ///
- /// If [addLineSeparator] is `true`, `\r\n` line separators will be added
- /// every 76 characters.
- ///
- /// If [encodePaddingCharacter] is `true`, the padding character `=` will be
- /// written as `%3D`.
- const Base64Encoder(
- {bool urlSafe: false,
- bool addLineSeparator: false,
- bool encodePaddingCharacter: false})
- : _urlSafe = urlSafe,
- _addLineSeparator = addLineSeparator,
- _pad = encodePaddingCharacter
- ? const [$percent, $3, $D]
- : const [$equal];
-
- /// Converts [bytes] to Base64.
- ///
- /// If [start] and [end] are provided, only the sublist `bytes.sublist(start,
- /// end)` is converted.
- String convert(List<int> bytes, [int start = 0, int end]) {
- RangeError.checkValidRange(start, end, bytes.length);
- if (end == null) end = bytes.length;
-
- var length = end - start;
- if (length == 0) return "";
-
- var lookup = _urlSafe ? _encodeTableUrlSafe : _encodeTable;
-
- // The total length of the 24-bit chunks.
- var remainderLength = length.remainder(3);
- var chunkLength = length - remainderLength;
-
- // The size of the base output.
- var baseOutputLength = (length ~/ 3) * 4;
- var remainderOutputLength = remainderLength > 0 ? 3 + _pad.length : 0;
-
- var outputLength = baseOutputLength + remainderOutputLength;
- if (_addLineSeparator) {
- // Add extra expected length to account for line separators.
- outputLength += ((outputLength - 1) ~/ _lineLength) * 2;
- }
- var out = new List<int>(outputLength);
-
- // Encode 24 bit chunks.
- var input = start;
- var output = 0;
- var chunks = 0;
- while (input < chunkLength) {
- // Get a 24-bit chunk from the next three input bytes. Mask each byte to
- // make sure we don't do something bad if the user passes in non-byte
- // ints.
- var chunk = (bytes[input++] << 16) & 0x00FF0000;
- chunk |= (bytes[input++] << 8) & 0x0000FF00;
- chunk |= bytes[input++] & 0x000000FF;
-
- // Split the 24-bit chunk into four 6-bit sections to encode as
- // characters.
- out[output++] = lookup.codeUnitAt(chunk >> 18);
- out[output++] = lookup.codeUnitAt((chunk >> 12) & 0x3F);
- out[output++] = lookup.codeUnitAt((chunk >> 6) & 0x3F);
- out[output++] = lookup.codeUnitAt(chunk & 0x3F);
-
- // Add an optional line separator for every 76 characters we emit; that
- // is, every 19 chunks.
- chunks++;
- if (_addLineSeparator && chunks == 19 && output < outputLength - 2) {
- out[output++] = $cr;
- out[output++] = $lf;
- chunks = 0;
- }
- }
-
- // If the input length isn't a multiple of 3, encode the remaining bytes and
- // add padding.
- if (remainderLength == 1) {
- var byte = bytes[input];
- out[output++] = lookup.codeUnitAt(byte >> 2);
- out[output++] = lookup.codeUnitAt((byte << 4) & 0x3F);
- out.setRange(output, output + _pad.length, _pad);
- out.setRange(output + _pad.length, output + 2 * _pad.length, _pad);
- } else if (remainderLength == 2) {
- var byte1 = bytes[input++];
- var byte2 = bytes[input];
- out[output++] = lookup.codeUnitAt(byte1 >> 2);
- out[output++] = lookup.codeUnitAt(((byte1 << 4) | (byte2 >> 4)) & 0x3F);
- out[output++] = lookup.codeUnitAt((byte2 << 2) & 0x3F);
- out.setRange(output, output + _pad.length, _pad);
- }
-
- return new String.fromCharCodes(out);
- }
-
- Base64EncoderSink startChunkedConversion(Sink<String> sink) {
- StringConversionSink stringSink = sink is StringConversionSink
- ? sink
- : new StringConversionSink.from(sink);
-
- return new Base64EncoderSink(stringSink, _urlSafe, _addLineSeparator);
- }
-}
diff --git a/lib/src/base64/encoder_sink.dart b/lib/src/base64/encoder_sink.dart
deleted file mode 100644
index 293735b..0000000
--- a/lib/src/base64/encoder_sink.dart
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2015, 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.
-
-import 'dart:convert';
-
-import 'encoder.dart';
-
-/// This is deprecated.
-///
-/// Use the `Base64Encoder` class in `dart:convert` instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class Base64EncoderSink extends ChunkedConversionSink<List<int>> {
- /// The encoder used to encode each chunk.
- final Base64Encoder _encoder;
-
- /// The underlying sink to which to emit the encoded strings.
- final ChunkedConversionSink<String> _outSink;
-
- /// The buffer of as-yet-unconverted bytes.
- ///
- /// This is used to ensure that we don't generate interstitial padding
- /// characters.
- final _buffer = new List<int>();
-
- /// The length of [_buffer]; that is, the number of unconverted bytes.
- var _bufferCount = 0;
-
- Base64EncoderSink(this._outSink, urlSafe, addLineSeparator)
- : _encoder = new Base64Encoder(
- urlSafe: urlSafe, addLineSeparator: addLineSeparator);
-
- void add(List<int> chunk) {
- var nextBufferCount = (chunk.length + _bufferCount) % 3;
- var decodableLength = _bufferCount + chunk.length - nextBufferCount;
-
- if (_bufferCount + chunk.length > _buffer.length) {
- _buffer.replaceRange(_bufferCount, _buffer.length,
- chunk.sublist(0, _buffer.length - _bufferCount));
- _buffer.addAll(chunk.sublist(_buffer.length - _bufferCount));
- } else {
- _buffer.replaceRange(_bufferCount, _bufferCount + chunk.length, chunk);
- }
-
- _outSink.add(_encoder.convert(_buffer, 0, decodableLength));
- _buffer.removeRange(0, decodableLength);
- _bufferCount = nextBufferCount;
- }
-
- void close() {
- if (_bufferCount > 0) {
- _outSink.add(_encoder.convert(_buffer.sublist(0, _bufferCount)));
- }
- _outSink.close();
- }
-}
-
diff --git a/lib/src/crypto_utils.dart b/lib/src/crypto_utils.dart
deleted file mode 100644
index 4af507c..0000000
--- a/lib/src/crypto_utils.dart
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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.
-
-import 'base64.dart';
-
-/// This class is deprecated.
-@Deprecated("Will be removed in crypto 1.0.0.")
-abstract class CryptoUtils {
- /// This is deprecated.
- ///
- /// Use `hex` from `package:convert` instead.
- static String bytesToHex(List<int> bytes) {
- var result = new StringBuffer();
- for (var part in bytes) {
- result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}');
- }
- return result.toString();
- }
-
- /// This is deprecated.
- ///
- /// Use `BASE64` from `dart:convert` instead.
- static String bytesToBase64(List<int> bytes,
- {bool urlSafe: false, bool addLineSeparator: false}) =>
- BASE64.encode(bytes,
- urlSafe: urlSafe, addLineSeparator: addLineSeparator);
-
- /// This is deprecated.
- ///
- /// Use `BASE64` from `dart:convert` instead.
- static List<int> base64StringToBytes(String input) => BASE64.decode(input);
-}
diff --git a/lib/src/hash.dart b/lib/src/hash.dart
index 9714f42..fad44ae 100644
--- a/lib/src/hash.dart
+++ b/lib/src/hash.dart
@@ -15,20 +15,11 @@
abstract class Hash extends Converter<List<int>, Digest> {
/// The internal block size of the hash in bytes.
///
- /// This is exposed for use by the [HMAC] class, which needs to know the block
+ /// This is exposed for use by the [Hmac] class, which needs to know the block
/// size for the [Hash] it uses.
int get blockSize;
- /// The sink for implementing the deprecated APIs that involved adding data
- /// directly to the [Hash] instance.
- ByteConversionSink _sink;
-
- /// The sink that [_sink] sends the [Digest] to once it finishes hashing.
- final DigestSink _innerSink = new DigestSink();
-
- Hash() {
- _sink = startChunkedConversion(_innerSink);
- }
+ const Hash();
Digest convert(List<int> data) {
var innerSink = new DigestSink();
@@ -39,25 +30,4 @@
}
ByteConversionSink startChunkedConversion(Sink<Digest> sink);
-
- /// This is deprecated.
- ///
- /// Use [startChunkedConversion] instead.
- @Deprecated("Will be removed in crypto 1.0.0.")
- Hash newInstance();
-
- /// This is deprecated.
- ///
- /// Use [convert] or [startChunkedConversion] instead.
- @Deprecated("Will be removed in crypto 1.0.0.")
- void add(List<int> data) => _sink.add(data);
-
- /// This is deprecated.
- ///
- /// Use [convert] or [startChunkedConversion] instead.
- @Deprecated("Will be removed in crypto 1.0.0.")
- List<int> close() {
- _sink.close();
- return _innerSink.value.bytes;
- }
}
diff --git a/lib/src/hmac.dart b/lib/src/hmac.dart
index f1b9de2..f5bf6bf 100644
--- a/lib/src/hmac.dart
+++ b/lib/src/hmac.dart
@@ -5,8 +5,6 @@
import 'dart:convert';
import 'dart:typed_data';
-import 'package:typed_data/typed_data.dart';
-
import 'digest.dart';
import 'digest_sink.dart';
import 'hash.dart';
@@ -51,75 +49,6 @@
new _HmacSink(sink, _hash, _key);
}
-/// This is deprecated.
-///
-/// Use [Hmac] instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class HMAC {
- final Hmac _hmac;
-
- /// The sink for implementing the deprecated APIs that involved adding data
- /// directly to the [HMAC] instance.
- _HmacSink _sink;
-
- /// The sink that [_sink] sends the [Digest] to once it finishes hashing.
- DigestSink _innerSink;
-
- /// The bytes from the message so far.
- final _message = new Uint8Buffer();
-
- /// Create an [HMAC] object from a [Hash] and a binary key.
- ///
- /// The key should be a secret shared between the sender and receiver of the
- /// message.
- HMAC(Hash hash, List<int> key) : _hmac = new Hmac(hash, key) {
- _innerSink = new DigestSink();
- _sink = _hmac.startChunkedConversion(_innerSink);
- }
-
- void add(List<int> data) {
- _message.addAll(data);
- _sink.add(data);
- }
-
- List<int> close() {
- _sink.close();
- return _innerSink.value.bytes;
- }
-
- List<int> get digest {
- if (_sink._isClosed) return _innerSink.value.bytes;
-
- // This may be called at any point while the message is being hashed, but
- // the [_HmacSink] only supports getting the value once. To make this work,
- // we just re-hash everything after we get the digest. It's redundant, but
- // this API is deprecated anyway.
- _sink.close();
- var bytes = _innerSink.value.bytes;
-
- _innerSink = new DigestSink();
- _sink = _hmac._hash.startChunkedConversion(_innerSink);
- _sink.add(_message);
-
- return bytes;
- }
-
- bool verify(List<int> digest) {
- var computedDigest = this.digest;
- if (digest.length != computedDigest.length) {
- throw new ArgumentError(
- 'Invalid digest size: ${digest.length} in HMAC.verify. '
- 'Expected: ${_hmac._hash.blockSize}.');
- }
-
- var result = 0;
- for (var i = 0; i < digest.length; i++) {
- result |= digest[i] ^ computedDigest[i];
- }
- return result == 0;
- }
-}
-
/// The concrete implementation of the HMAC algorithm.
class _HmacSink extends ByteConversionSink {
/// The sink for the outer hash computation.
diff --git a/lib/src/md5.dart b/lib/src/md5.dart
index 1374df7..69e3c32 100644
--- a/lib/src/md5.dart
+++ b/lib/src/md5.dart
@@ -18,7 +18,7 @@
///
/// **Warning**: MD5 has known collisions and should only be used when required
/// for backwards compatibility.
-final md5 = new MD5();
+final md5 = new MD5._();
/// An implementation of the [MD5][rfc] hash function.
///
@@ -32,13 +32,7 @@
class MD5 extends Hash {
final int blockSize = 16 * bytesPerWord;
- /// This constructor is deprecated.
- ///
- /// Use [md5] instead.
- @Deprecated("Will be removed in crypto 1.0.0.")
- MD5();
-
- MD5 newInstance() => new MD5();
+ MD5._();
ByteConversionSink startChunkedConversion(Sink<Digest> sink) =>
new ByteConversionSink.from(new _MD5Sink(sink));
diff --git a/lib/src/sha1.dart b/lib/src/sha1.dart
index 9bb6411..0410761 100644
--- a/lib/src/sha1.dart
+++ b/lib/src/sha1.dart
@@ -25,22 +25,10 @@
Sha1._();
- Sha1 newInstance() => new Sha1._();
-
ByteConversionSink startChunkedConversion(Sink<Digest> sink) =>
new ByteConversionSink.from(new _Sha1Sink(sink));
}
-/// This class is deprecated.
-///
-/// Use [sha1] instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class SHA1 extends Sha1 {
- SHA1() : super._();
-
- SHA1 newInstance() => new SHA1();
-}
-
/// The concrete implementation of [Sha1].
///
/// This is separate so that it can extend [HashBase] without leaking additional
diff --git a/lib/src/sha256.dart b/lib/src/sha256.dart
index 61cd72f..0145363 100644
--- a/lib/src/sha256.dart
+++ b/lib/src/sha256.dart
@@ -34,16 +34,6 @@
new ByteConversionSink.from(new _Sha256Sink(sink));
}
-/// This class is deprecated.
-///
-/// Use [sha256] instead.
-@Deprecated("Will be removed in crypto 1.0.0.")
-class SHA256 extends Sha256 {
- SHA256() : super._();
-
- SHA256 newInstance() => new SHA256();
-}
-
/// Data from a non-linear function that functions as reproducible noise.
const List<int> _noise = const [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
diff --git a/pubspec.yaml b/pubspec.yaml
index 16be73c..a20644f 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: crypto
-version: 0.9.2
+version: 1.0.0
author: Dart Team <misc@dartlang.org>
description: Library of cryptographic functions.
homepage: https://www.github.com/dart-lang/crypto
@@ -7,7 +7,5 @@
sdk: '>=1.8.0 <2.0.0'
dependencies:
convert: '^1.0.0'
- charcode: '^1.1.0'
- typed_data: '^1.0.0'
dev_dependencies:
test: '>=0.12.0 <0.13.0'
diff --git a/test/base64_test.dart b/test/base64_test.dart
deleted file mode 100644
index a0ea9ee..0000000
--- a/test/base64_test.dart
+++ /dev/null
@@ -1,308 +0,0 @@
-// 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.
-
-import 'dart:async';
-import 'dart:convert';
-import 'dart:math';
-
-import "package:charcode/ascii.dart";
-import "package:crypto/crypto.dart";
-import "package:test/test.dart";
-
-void main() {
- group("encoder", () {
- test("for simple inputs", () {
- expect(BASE64.encode([]), equals(''));
- expect(BASE64.encode([$f]), equals('Zg=='));
- expect(BASE64.encode([$f, $o]), equals('Zm8='));
- expect(BASE64.encode([$f, $o, $o]), equals('Zm9v'));
- expect(BASE64.encode([$f, $o, $o, $b]), equals('Zm9vYg=='));
- expect(BASE64.encode([$f, $o, $o, $b, $a]), equals('Zm9vYmE='));
- expect(BASE64.encode([$f, $o, $o, $b, $a, $r]), equals('Zm9vYmFy'));
- });
-
- test("for inputs with zeroes", () {
- expect(BASE64.encode([0]), equals('AA=='));
- expect(BASE64.encode([0, 0]), equals('AAA='));
- expect(BASE64.encode([0, 0, 0]), equals('AAAA'));
- expect(BASE64.encode([0, 0, 0, 0]), equals('AAAAAA=='));
- });
-
- test("for a large input with line separators", () {
- expect(
- BASE64.encode(
- UTF8.encode(
- "Man is distinguished, not only by his reason, but by this "
- "singular passion from other animals, which is a lust of the "
- "mind, that by a perseverance of delight in the continued "
- "and indefatigable generation of knowledge, exceeds the "
- "short vehemence of any carnal pleasure."),
- addLineSeparator: true),
- equals(
- "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1"
- "dCBieSB0aGlz\r\n"
- "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBh"
- "IGx1c3Qgb2Yg\r\n"
- "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0"
- "aGUgY29udGlu\r\n"
- "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBl"
- "eGNlZWRzIHRo\r\n"
- "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="));
- });
-
- test("for a large input without line separators", () {
- expect(
- BASE64.encode(
- UTF8.encode(
- "Man is distinguished, not only by his reason, but by this "
- "singular passion from other animals, which is a lust of the "
- "mind, that by a perseverance of delight in the continued "
- "and indefatigable generation of knowledge, exceeds the "
- "short vehemence of any carnal pleasure.")),
- equals(
- "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1"
- "dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3"
- "aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFu"
- "Y2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxl"
- "IGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhl"
- "bWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="));
- });
-
- test("for chunked input", () {
- expect(_encodeChunked([
- [102, 102],
- [111, 102],
- [
- 111, 111, 102, 111, 111, 98, 102, 111, 111, 98, 97, 102, 111, 111,
- 98, 97, 114
- ]
- ]), equals("ZmZvZm9vZm9vYmZvb2JhZm9vYmFy"));
-
- expect(_encodeChunked([[196, 16], [], [158], [196]]), equals("xBCexA=="));
- expect(_encodeChunked([[196, 16], [158, 196], [], []]),
- equals("xBCexA=="));
- expect(_encodeChunked([[196], [], [16], [], [], [158], [], [196]]),
- equals("xBCexA=="));
- expect(_encodeChunked([[196], [], [16], [158, 196], [], []]),
- equals("xBCexA=="));
- expect(_encodeChunked([[], [196], [], [], [16, 158], [], [196]]),
- equals("xBCexA=="));
- expect(_encodeChunked([[], [196], [16, 158, 196], []]),
- equals("xBCexA=="));
- expect(_encodeChunked([[196, 16, 158], [], [], [196]]),
- equals("xBCexA=="));
- expect(_encodeChunked([[196, 16, 158], [], [196], []]),
- equals("xBCexA=="));
- expect(_encodeChunked([[196, 16, 158, 196], [], [], []]),
- equals("xBCexA=="));
- });
-
- test('with a URL-safe alphabet', () {
- expect(BASE64.encode(BASE64.decode('+/A='), urlSafe: true),
- equals('-_A='));
- });
-
- test('with a percent-encoded padding character', () {
- expect(BASE64.encode([2, 8], encodePaddingCharacter: true),
- equals('Agg%3D'));
- });
-
- test('with the old API', () {
- expect(CryptoUtils.bytesToBase64([]), equals(''));
- expect(CryptoUtils.bytesToBase64([$f]), equals('Zg=='));
- expect(CryptoUtils.bytesToBase64([$f, $o]), equals('Zm8='));
- expect(CryptoUtils.bytesToBase64([$f, $o, $o]), equals('Zm9v'));
- expect(CryptoUtils.bytesToBase64([$f, $o, $o, $b]), equals('Zm9vYg=='));
- expect(CryptoUtils.bytesToBase64([$f, $o, $o, $b, $a]),
- equals('Zm9vYmE='));
- expect(CryptoUtils.bytesToBase64([$f, $o, $o, $b, $a, $r]),
- equals('Zm9vYmFy'));
- });
- });
-
- group("decoder", () {
- test("for simple inputs", () {
- expect(BASE64.decode(''), equals([]));
- expect(BASE64.decode('Zg=='), equals([$f]));
- expect(BASE64.decode('Zm8='), equals([$f, $o]));
- expect(BASE64.decode('Zm9v'), equals([$f, $o, $o]));
- expect(BASE64.decode('Zm9vYg=='), equals([$f, $o, $o, $b]));
- expect(BASE64.decode('Zm9vYmE='), equals([$f, $o, $o, $b, $a]));
- expect(BASE64.decode('Zm9vYmFy'), equals([$f, $o, $o, $b, $a, $r]));
- });
-
- test("for inputs with zeroes", () {
- expect(BASE64.decode('AA=='), equals([0]));
- expect(BASE64.decode('AAA='), equals([0, 0]));
- expect(BASE64.decode('AAAA'), equals([0, 0, 0]));
- expect(BASE64.decode('AAAAAA=='), equals([0, 0, 0, 0]));
- });
-
- test("for a large input with line separators", () {
- expect(
- BASE64.decode(
- "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1"
- "dCBieSB0aGlz\r\n"
- "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBh"
- "IGx1c3Qgb2Yg\r\n"
- "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0"
- "aGUgY29udGlu\r\n"
- "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBl"
- "eGNlZWRzIHRo\r\n"
- "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="),
- equals(UTF8.encode(
- "Man is distinguished, not only by his reason, but by this "
- "singular passion from other animals, which is a lust of the "
- "mind, that by a perseverance of delight in the continued and "
- "indefatigable generation of knowledge, exceeds the short "
- "vehemence of any carnal pleasure.")));
- });
-
- test("for a large input without line separators", () {
- expect(
- BASE64.decode(
- "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1"
- "dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3"
- "aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFu"
- "Y2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxl"
- "IGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhl"
- "bWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="),
- equals(UTF8.encode(
- "Man is distinguished, not only by his reason, but by this "
- "singular passion from other animals, which is a lust of the "
- "mind, that by a perseverance of delight in the continued and "
- "indefatigable generation of knowledge, exceeds the short "
- "vehemence of any carnal pleasure.")));
- });
-
- test("for chunked input", () {
- expect(_decodeChunked(['YmFz', 'ZTY', '0I', 'GRlY29kZXI=']), equals([
- 98, 97, 115, 101, 54, 52, 32, 100, 101, 99, 111, 100, 101, 114
- ]));
- });
-
- test("for chunked input containing zeroes", () {
- expect(_decodeChunked(['AAAA', 'AAA=', 'AA==', '']),
- equals([0, 0, 0, 0, 0, 0]));
-
- expect(_decodeChunked(["A", "", "BCD"]), equals([0, 16, 131]));
- expect(_decodeChunked(["A", "BCD", "", ""]), equals([0, 16, 131]));
- expect(_decodeChunked(["A", "B", "", "", "CD", ""]),
- equals([0, 16, 131]));
- expect(_decodeChunked(["", "A", "BC", "", "D"]), equals([0, 16, 131]));
- expect(_decodeChunked(["", "AB", "C", "", "", "D"]),
- equals([0, 16, 131]));
- expect(_decodeChunked(["AB", "CD", ""]), equals([0, 16, 131]));
- expect(_decodeChunked(["", "ABC", "", "D"]), equals([0, 16, 131]));
- expect(_decodeChunked(["", "ABC", "D", ""]), equals([0, 16, 131]));
- expect(_decodeChunked(["", "", "ABCD", ""]), equals([0, 16, 131]));
- expect(_decodeChunked(["A", "B", "C", "D"]), equals([0, 16, 131]));
- expect(_decodeChunked(["", "A", "B", "C", "D", ""]),
- equals([0, 16, 131]));
- expect(_decodeChunked(["", "A", "B", "", "", "C", "", "D", ""]),
- equals([0, 16, 131]));
- });
-
- test("for chunked input with encoded padding", () {
- expect(_decodeChunked(['AA%', '3D', '%', '3', 'DEFGZ']),
- equals(BASE64.decode('AA==EFGZ')));
- });
-
- test('with a URL-safe alphabet', () {
- expect(BASE64.decode('-_A='), equals(BASE64.decode('+/A=')));
- });
-
- test('with a percent-encoded padding character', () {
- expect(BASE64.decode('Agg%3D'), equals([2, 8]));
- });
-
- test("with the old API", () {
- expect(CryptoUtils.base64StringToBytes(''), equals([]));
- expect(CryptoUtils.base64StringToBytes('Zg=='), equals([$f]));
- expect(CryptoUtils.base64StringToBytes('Zm8='), equals([$f, $o]));
- expect(CryptoUtils.base64StringToBytes('Zm9v'), equals([$f, $o, $o]));
- expect(CryptoUtils.base64StringToBytes('Zm9vYg=='),
- equals([$f, $o, $o, $b]));
- expect(CryptoUtils.base64StringToBytes('Zm9vYmE='),
- equals([$f, $o, $o, $b, $a]));
- expect(CryptoUtils.base64StringToBytes('Zm9vYmFy'),
- equals([$f, $o, $o, $b, $a, $r]));
- });
-
- group("rejects", () {
- test("input of the wrong length", () {
- expect(() => BASE64.decode('A'), throwsFormatException);
- expect(() => BASE64.decode('AB'), throwsFormatException);
- expect(() => BASE64.decode('ABz'), throwsFormatException);
- expect(() => BASE64.decode('ABzdE'), throwsFormatException);
- expect(() => BASE64.decode('ABzdEf'), throwsFormatException);
- expect(() => BASE64.decode('ABzdEfg'), throwsFormatException);
- });
-
- test("input with invalid characters", () {
- expect(() => BASE64.decode('AB~'), throwsFormatException);
- });
-
- test("chunked input of the wrong length", () {
- expect(() => _decodeChunked(['ABz']), throwsFormatException);
- expect(() => _decodeChunked(['AB', 'Lx', 'z', 'xx']),
- throwsFormatException);
- });
-
- test("input with the wrong padding", () {
- expect(() => BASE64.decode('A=='), throwsFormatException);
- expect(() => BASE64.decode('AB='), throwsFormatException);
- expect(() => BASE64.decode('ABz=='), throwsFormatException);
- expect(() => BASE64.decode('ABzdE='), throwsFormatException);
- });
-
- test("input with the wrong encoded padding", () {
- expect(() => BASE64.decode('A%3D%3D'), throwsFormatException);
- expect(() => BASE64.decode('AB%3D'), throwsFormatException);
- expect(() => BASE64.decode('ABz%3D%3D'), throwsFormatException);
- expect(() => BASE64.decode('ABzdE%3D'), throwsFormatException);
- });
- });
- });
-
- test('successfully round-trips data', () {
- for (var i = 0; i < 10; i++) {
- for (var j = 0; j < 256 - i; j++) {
- var data = new List.filled(i, j);
- expect(BASE64.decode(BASE64.encode(data)), equals(data));
- }
- }
- });
-}
-
-/// Performs chunked Base64 decoding of [chunks] and returns the result as a
-/// byte array.
-List<int> _decodeChunked(Iterable<String> chunks) {
- var bytes;
- var innerSink = new ByteConversionSink.withCallback(
- (result) => bytes = result);
- var sink = BASE64.decoder.startChunkedConversion(innerSink);
-
- for (var chunk in chunks) {
- sink.add(chunk);
- }
- sink.close();
-
- return bytes;
-}
-
-/// Performs chunked Base64 encoding of [chunks] and returns the result.
-String _encodeChunked(Iterable<List<int>> chunks) {
- var string;
- var innerSink = new StringConversionSink.withCallback(
- (result) => string = result);
- var sink = BASE64.encoder.startChunkedConversion(innerSink);
-
- for (var chunk in chunks) {
- sink.add(chunk);
- }
- sink.close();
-
- return string;
-}
diff --git a/test/sha1_test.dart b/test/sha1_test.dart
index e3471c3..552b862 100644
--- a/test/sha1_test.dart
+++ b/test/sha1_test.dart
@@ -8,22 +8,6 @@
import "package:test/test.dart";
void main() {
- group("with the old API", () {
- test('add may not be called after close', () {
- var sha = new SHA1();
- sha.close();
- expect(() => sha.add([0]), throwsStateError);
- });
-
- test('close returns the same digest repeatedly', () {
- var sha = new SHA1();
- var digest = sha.close();
- expect(sha.close(), equals(digest));
- expect(sha.close(), equals(digest));
- expect(sha.close(), equals(digest));
- });
- });
-
group("with a chunked converter", () {
test('add may not be called after close', () {
var sink = sha1.startChunkedConversion(new StreamController().sink);
diff --git a/test/sha256_test.dart b/test/sha256_test.dart
index c2b6d3e..75fb9e3 100644
--- a/test/sha256_test.dart
+++ b/test/sha256_test.dart
@@ -10,22 +10,6 @@
import "utils.dart";
void main() {
- group("with the old API", () {
- test('add may not be called after close', () {
- var sha = new SHA256();
- sha.close();
- expect(() => sha.add([0]), throwsStateError);
- });
-
- test('close returns the same digest repeatedly', () {
- var sha = new SHA256();
- var digest = sha.close();
- expect(sha.close(), equals(digest));
- expect(sha.close(), equals(digest));
- expect(sha.close(), equals(digest));
- });
- });
-
group("with a chunked converter", () {
test('add may not be called after close', () {
var sink = sha256.startChunkedConversion(new StreamController().sink);