Skip to content

Commit

Permalink
Merge pull request #87 from bugsnag/release-v1.2.1
Browse files Browse the repository at this point in the history
Release v1.2.1
  • Loading branch information
robert-smartbear authored Sep 18, 2024
2 parents 4c4e075 + 669a9fb commit beb5406
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## 1.2.1 (2024-09-18)

### Bug fixes

* Fixed an exception thrown when no source of cryptographically secure random numbers is available [86](https://github.com/bugsnag/bugsnag-flutter-performance/pull/86)

## 1.2.0 (2024-09-13)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.2.1
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,5 @@ class ResourceAttributesProviderImpl implements ResourceAttributesProvider {
return "Unknown";
}

static String get _getSDKVersion => '1.2.0';
static String get _getSDKVersion => '1.2.1';
}
45 changes: 41 additions & 4 deletions packages/bugsnag_flutter_performance/lib/src/util/random.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
import 'dart:math';

BigInt randomSpanId() {
return randomValue(8);
return randomValue(8, false);
}

BigInt randomTraceId() {
return randomValue(16);
return randomValue(16, true);
}

BigInt randomValue(int length) {
final random = Random.secure();
BigInt randomValue(int length, bool secure) {
final random = _Random(secure);
BigInt result = BigInt.from(random.nextInt(256) & 0xff);
for (var i = 1; i < length; i++) {
int byte = random.nextInt(256);
result = (result << 8) | BigInt.from(byte & 0xff);
}
return result;
}

class _Random {
static final _sharedRandom = _createSharedRandom();
late final Random? _secureRandom;
final bool secure;

_Random(this.secure) {
try {
if (secure) {
_secureRandom = Random.secure();
}
} catch (_) {
// If the platform doesn't provide a secure random source then we fall back on a less secure version
}
}

int nextInt(int max) {
try {
if (_secureRandom != null) {
return _secureRandom!.nextInt(max);
}
} catch (_) {
// When the system runs out of entropy, we fall back on a less secure random number source
// Although the documentation doesn't mention it, nextInt can throw
}
return _sharedRandom.nextInt(max);
}

static Random _createSharedRandom() {
try {
final secureRandom = Random.secure();
return Random(secureRandom.nextInt(1 << 32));
} catch (_) {
return Random();
}
}
}
2 changes: 1 addition & 1 deletion packages/bugsnag_flutter_performance/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bugsnag_flutter_performance
description: BugSnag performance monitoring tool for Flutter apps
version: 1.2.0
version: 1.2.1
homepage: https://www.bugsnag.com/
documentation: https://docs.bugsnag.com/performance/flutter/
repository: https://github.com/bugsnag/bugsnag-flutter-performance
Expand Down

0 comments on commit beb5406

Please sign in to comment.