샘플
crypto 3.0.6: Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag
검증된 샘플 — pub crypto 3.0.6: Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag. dart 3 · linux…
sha256:09b939ee857b27e516b256d5df83641ab0732701a6522d5cdfaf787afdce7c3e
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
dart linux x64 dart dart pub
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- Enforce package:crypto internal invariant assertions and runtime behavior under Dart's --enable-asserts flag
- 패키지
- 심벌
-
- HashSink
- Hmac
- Digest
- sha256
- 환경
- dart
- 생성일
- 2026-08-17T03:18:36Z
컨트랙트
- 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
파일
- .gitignore
- NOTES.md
- csx.json
- lib/pub_crypto_config.dart
- pubspec.lock
- pubspec.yaml
- test/contract.dart
- test/pub_crypto_config_test.dart
소스
# 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);
});
}