Remove dependency on pkg/uuid
Use a home-rolled version
diff --git a/lib/src/http.dart b/lib/src/http.dart
index 9f8974d..c3a60d3 100644
--- a/lib/src/http.dart
+++ b/lib/src/http.dart
@@ -10,7 +10,6 @@
import 'package:http/http.dart' as http;
import 'package:http_throttle/http_throttle.dart';
import 'package:stack_trace/stack_trace.dart';
-import 'package:uuid/uuid.dart';
import 'command_runner.dart';
import 'io.dart';
@@ -31,7 +30,7 @@
final PUB_API_HEADERS = const {'Accept': 'application/vnd.pub.v2+json'};
/// A unique ID to identify this particular invocation of pub.
-final _sessionId = new Uuid().v4() as String;
+final _sessionId = createUuid();
/// An HTTP client that transforms 40* errors and socket exceptions into more
/// user-friendly error messages.
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index f07253d..259d228 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -824,3 +824,26 @@
Iterable/*<T>*/ combineIterables/*<T>*/(
Iterable/*<T>*/ iter1, Iterable/*<T>*/ iter2) =>
iter1.toList()..addAll(iter2);
+
+/// Returns a UUID in v4 format as a `String`.
+///
+/// If [bytes] is provided, it must be length 16 and have values between `0` and
+/// `255` inclusive.
+///
+/// If [bytes] is not provided, it is generated using `Random.secure`.
+String createUuid([List<int> bytes]) {
+ var rnd = new math.Random.secure();
+
+ // See http://www.cryptosys.net/pki/uuid-rfc4122.html for notes
+ bytes ??= new List<int>.generate(16, (_) => rnd.nextInt(256));
+ bytes[6] = (bytes[6] & 0x0F) | 0x40;
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
+
+ var chars = bytes
+ .map((b) => b.toRadixString(16).padLeft(2, '0'))
+ .join()
+ .toUpperCase();
+
+ return '${chars.substring(0, 8)}-${chars.substring(8, 12)}-'
+ '${chars.substring(12, 16)}-${chars.substring(16, 20)}-${chars.substring(20, 32)}';
+}
diff --git a/pubspec.yaml b/pubspec.yaml
index 33c456b..bdf3eea 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -31,7 +31,6 @@
stack_trace: "^1.0.0"
stream_channel: "^1.4.0"
string_scanner: "^1.0.0"
- uuid: "^0.5.0"
watcher: "^0.9.2"
web_socket_channel: "^1.0.0"
yaml: "^2.0.0"
diff --git a/test/utils_test.dart b/test/utils_test.dart
index feae466..4f0f09d 100644
--- a/test/utils_test.dart
+++ b/test/utils_test.dart
@@ -102,4 +102,26 @@
expect(niceDuration(new Duration(minutes: 1)), equals("1:00.0s"));
});
});
+
+ group('uuid', () {
+ var uuidRegexp = new RegExp("^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-"
+ r"[8-9A-B][0-9A-F]{3}-[0-9A-F]{12}$");
+
+ test("min value is valid", () {
+ var uuid = createUuid(new List<int>.filled(16, 0));
+ expect(uuid, matches(uuidRegexp));
+ expect(uuid, "00000000-0000-4000-8000-000000000000");
+ });
+ test("max value is valid", () {
+ var uuid = createUuid(new List<int>.filled(16, 255));
+ expect(uuid, matches(uuidRegexp));
+ expect(uuid, "FFFFFFFF-FFFF-4FFF-BFFF-FFFFFFFFFFFF");
+ });
+ test("random values are valid", () {
+ for (var i = 0; i < 100; i++) {
+ var uuid = createUuid();
+ expect(uuid, matches(uuidRegexp));
+ }
+ });
+ });
}