Sample
crypto 3.0.6: Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag
Verified sample for pub crypto 3.0.6: Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag. The…
sha256:09b939ee857b27e516b256d5df83641ab0732701a6522d5cdfaf787afdce7c3e
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
dart linux x64 dart dart pub
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| dart 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-17 |
| dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · pub@1 |
2026-08-18 |
Case
HOW- Goal
- Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag
- Packages
- Symbols
-
- HashSink
- Hmac
- Digest
- sha256
- Environment
- dart
- Created
- 2026-08-17T03:18:36Z
Contract
- Instantiating HashSink with signatureBytes less than 8 bypasses checks and produces a digest in default mode, but throws AssertionError only when Dart is run with the --enable-asserts flag.
- assert that digest instances compare by value with == while comparing their bytes property checks reference identity
- assert that Hmac key list elements outside 0..255 are truncated to 8-bit integers without throwing an ArgumentError
- assert that chunked conversion sinks emit a Digest to the destination sink only after close() is called
Files
- .gitignore
- NOTES.md
- csx.json
- lib/pub_crypto_config.dart
- pubspec.lock
- pubspec.yaml
- test/contract.dart
- test/pub_crypto_config_test.dart
Source
# Generated by `dart pub`.
.dart_tool/
# package:crypto Invariant Assertions and Runtime Flag Traps
## Search Findings
`search_known_solution` returned existing published sample `sha256:952bc1f38576d888d49cb6f0448660430b83ce93bb4791d17a4c8e36dc3ca9a5` ("Hash and HMAC in Dart with package:crypto, and compare the result correctly"). That sample covers standard hash vectors.
## What a Model Would Expect
A model expects internal constructor assertions (such as `signatureBytes >= 8` in `HashSink`) or input validation checks to throw runtime exceptions (`ArgumentError` or `StateError`) unconditionally across all Dart execution modes.
## How the Wrong Configuration Fails
Without passing `--enable-asserts` to the Dart VM runtime, assertion checks in `package:crypto` are bypassed completely, silently proceeding with invalid signature lengths and returning malformed digest outputs instead of failing with an exception.
{"case":{"believed":"Internal constructor invariants in package:crypto throw an ArgumentError or StateError on invalid configurations regardless of Dart runtime flags.","caseId":"case:sha256:fd14150debc552b3021500eb9ea170648cd9b13c1052a7979153e0a3dd7c53a2","contract":["Instantiating HashSink with signatureBytes less than 8 bypasses checks and produces a digest in default mode, but throws AssertionError only when Dart is run with the --enable-asserts flag.","assert that digest instances compare by value with == while comparing their bytes property checks reference identity","assert that Hmac key list elements outside 0..255 are truncated to 8-bit integers without throwing an ArgumentError","assert that chunked conversion sinks emit a Digest to the destination sink only after close() is called"],"goal":"Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag","kind":"HOW","packages":["pkg:pub/crypto@3.0.6"],"schemaVersion":1,"symbols":["HashSink","Hmac","Digest","sha256"]},"contractCommand":["dart","--enable-asserts","test/contract.dart"],"environment":{"arch":"x64","ecosystem":"pub","executionContext":"dart","language":"dart","os":"linux","packageManager":"pub","runtime":"dart","schemaVersion":1},"license":"MIT-0","packages":["pkg:pub/crypto@3.0.6"],"schemaVersion":1,"symbols":["HashSink","Hmac","Digest","sha256"],"verifierAdapter":"pub@1"}
int calculate() {
return 6 * 7;
}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
collection:
dependency: transitive
description:
name: collection
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
url: "https://pub.dev"
source: hosted
version: "1.19.1"
crypto:
dependency: "direct main"
description:
name: crypto
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
url: "https://pub.dev"
source: hosted
version: "3.0.6"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://pub.dev"
source: hosted
version: "1.4.0"
sdks:
dart: ">=3.5.0 <4.0.0"
name: csx_dart_crypto
description: Minimal project for package crypto testing.
publish_to: none
environment:
sdk: '>=3.0.0 <4.0.0'
dependencies:
crypto: 3.0.6
import 'dart:convert';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
// ignore: implementation_imports
import 'package:crypto/src/hash_sink.dart';
class CustomHash extends Hash {
final int signatureBytes;
const CustomHash({this.signatureBytes = 4});
@override
int get blockSize => 64;
@override
ByteConversionSink startChunkedConversion(Sink<Digest> sink) =>
ByteConversionSink.from(_CustomSink(sink, signatureBytes));
}
class _CustomSink extends HashSink {
_CustomSink(Sink<Digest> sink, int sigBytes)
: super(sink, 16, signatureBytes: sigBytes);
@override
Uint32List get digest => Uint32List(8);
@override
void updateHash(Uint32List chunk) {}
}
class DestinationSink implements Sink<Digest> {
Digest? value;
@override
void add(Digest data) {
value = data;
}
@override
void close() {}
}
void main() {
// 1. Verify --enable-asserts flag is active for this execution
bool assertsEnabled = false;
assert(() {
assertsEnabled = true;
return true;
}());
if (!assertsEnabled) {
throw StateError('Contract requires Dart VM --enable-asserts flag to be active.');
}
// 2. HashSink with signatureBytes < 8 throws AssertionError with --enable-asserts
bool caughtAssertion = false;
try {
const CustomHash(signatureBytes: 4).convert([1, 2, 3]);
} on AssertionError {
caughtAssertion = true;
}
if (!caughtAssertion) {
throw StateError('Expected AssertionError for signatureBytes < 8 under --enable-asserts');
}
// 3. Digest equality vs bytes reference identity
final digestA = sha256.convert([10, 20, 30]);
final digestB = sha256.convert([10, 20, 30]);
if (digestA != digestB) {
throw StateError('Digest instances with identical bytes must compare equal using ==');
}
if (digestA.bytes == digestB.bytes) {
throw StateError('Digest.bytes comparison must evaluate reference identity (false for separate lists)');
}
// 4. Hmac byte truncation for integer values outside 0..255
final hmacOverflow = Hmac(sha256, [256, -1, 300]);
final hmacTruncated = Hmac(sha256, [0, 255, 44]);
final sampleInput = utf8.encode('test');
if (hmacOverflow.convert(sampleInput) != hmacTruncated.convert(sampleInput)) {
throw StateError('Hmac must truncate integer key elements outside 0..255 without throwing ArgumentError');
}
// 5. Chunked conversion requires close() before digest emission
final destSink = DestinationSink();
final chunkedSink = sha256.startChunkedConversion(destSink);
chunkedSink.add(utf8.encode('hello'));
if (destSink.value != null) {
throw StateError('Chunked conversion sink must not emit Digest before close() is called');
}
chunkedSink.close();
if (destSink.value == null) {
throw StateError('Chunked conversion sink must emit Digest after close() is called');
}
}
import 'package:pub_crypto_config/pub_crypto_config.dart';
import 'package:test/test.dart';
void main() {
test('calculate', () {
expect(calculate(), 42);
});
}