-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from bugsnag/release-v1.2.1
Release v1.2.1
- Loading branch information
Showing
5 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.2.0 | ||
1.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 41 additions & 4 deletions
45
packages/bugsnag_flutter_performance/lib/src/util/random.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters