-
-
Notifications
You must be signed in to change notification settings - Fork 3
fix: snowden mode could not decrypt its own output #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /// {@template qr_plus_read_error} | ||
| /// Describes why a scanned QR code could not be turned into usable data. | ||
| /// | ||
| /// Without this, a failure to decode is indistinguishable from the camera | ||
| /// simply not seeing anything: the reader silently ignores the code and the | ||
| /// user is left staring at a viewfinder that never reacts. Surfacing the reason | ||
| /// lets the app tell the user what is wrong, and makes misconfiguration | ||
| /// (notably a mismatched encryption key) obvious instead of invisible. | ||
| /// {@endtemplate} | ||
| enum QrPlusReadError { | ||
| /// {@macro qr_plus_read_error} | ||
| /// | ||
| /// The QR code was read, but its contents could not be decrypted or parsed. | ||
| /// | ||
| /// In snowden mode this almost always means the reader and the renderer | ||
| /// disagree on the encryption key, or the code was not produced by | ||
| /// package:qr_plus at all. | ||
| unreadable, | ||
|
|
||
| /// {@macro qr_plus_read_error} | ||
| /// | ||
| /// The data was decoded, but it was created with a different QrPlusMode | ||
| /// than the reader is configured with. The renderer and reader must use the | ||
| /// same mode. | ||
| modeMismatch, | ||
| } |
This file contains hidden or 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,4 +1,5 @@ | ||
| export 'src/connectivity_result_extension.dart'; | ||
| export 'src/qr_plus_authenticity.dart'; | ||
| export 'src/qr_plus_read_error.dart'; | ||
| export 'src/screen_recorder_status.dart'; | ||
| export 'src/string_extension.dart'; |
This file contains hidden or 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 hidden or 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
130 changes: 130 additions & 0 deletions
130
test/feature/reader/cubit/qr_plus_reader_error_test.dart
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Tests for the onReadError path. | ||
| // | ||
| // Before this existed, a QR code that could not be decrypted was discarded in | ||
| // silence: no callback, no log, nothing. That made a total crypto failure look | ||
| // identical to "the camera isn't seeing the code", which is exactly what made | ||
| // the encrypt 5.0.3 IV regression so slow to diagnose. | ||
|
|
||
| import 'package:bloc_test/bloc_test.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mocktail/mocktail.dart'; | ||
| import 'package:qr_plus/qr_plus.dart'; | ||
| import 'package:qr_plus/src/feature/reader/cubit/cubit.dart'; | ||
| import 'package:qr_plus/src/model/model.dart'; | ||
| import 'package:qr_plus/src/repository/repository.dart'; | ||
|
|
||
| class DataCallback { | ||
| void call(String s, List<QrPlusAuthenticity> a) {} | ||
| } | ||
|
|
||
| class ErrorCallback { | ||
| void call(QrPlusReadError error) {} | ||
| } | ||
|
|
||
| class MockDataCallback extends Mock implements DataCallback {} | ||
|
|
||
| class MockErrorCallback extends Mock implements ErrorCallback {} | ||
|
|
||
| class MockNtpRepository extends Mock implements NtpRepository {} | ||
|
|
||
| void main() { | ||
| late DataCallback onData; | ||
| late ErrorCallback onReadError; | ||
| late NtpRepository ntpRepository; | ||
|
|
||
| const mode = QrPlusMode.snowden( | ||
| encryptionKey: 'abcdefghijklmnopqrstuvwx', | ||
| ttl: Duration(minutes: 5), | ||
| crumbs: 2, | ||
| ); | ||
|
|
||
| setUp(() { | ||
| registerFallbackValue(QrPlusReadError.unreadable); | ||
| onData = MockDataCallback(); | ||
| onReadError = MockErrorCallback(); | ||
| ntpRepository = MockNtpRepository(); | ||
|
|
||
| when(() => ntpRepository.now).thenReturn(DateTime(2026)); | ||
| when(() => onReadError.call(any<QrPlusReadError>())).thenAnswer((_) {}); | ||
| }); | ||
|
|
||
| group('QrPlusReaderCubit onReadError', () { | ||
| blocTest<QrPlusReaderCubit, QrPlusReaderState>( | ||
| 'is called with unreadable ' | ||
| 'when the code cannot be decrypted', | ||
| build: () => QrPlusReaderCubit( | ||
| mode: mode, | ||
| onData: onData.call, | ||
| onReadError: onReadError.call, | ||
| ntpRepository: ntpRepository, | ||
| ), | ||
| act: (cubit) => cubit.onRawData('not-a-qr-plus-code'), | ||
| verify: (_) => verify( | ||
| () => onReadError.call(QrPlusReadError.unreadable), | ||
| ).called(1), | ||
| ); | ||
|
|
||
| blocTest<QrPlusReaderCubit, QrPlusReaderState>( | ||
| 'is called with unreadable ' | ||
| 'when the code was encrypted with a different key', | ||
| build: () => QrPlusReaderCubit( | ||
| mode: mode, | ||
| onData: onData.call, | ||
| onReadError: onReadError.call, | ||
| ntpRepository: ntpRepository, | ||
| ), | ||
| act: (cubit) { | ||
| final foreign = QrPlusDataCrumb.authentic( | ||
| uid: 'uid', | ||
| data: 'data', | ||
| mode: const QrPlusMode.snowden( | ||
| encryptionKey: 'XXXXXXXXXXXXXXXXXXXXXXXX', | ||
| ), | ||
| timestamp: DateTime.utc(2026), | ||
| index: 0, | ||
| crumbs: 2, | ||
| ).toQrString(); | ||
|
|
||
| return cubit.onRawData(foreign); | ||
| }, | ||
| verify: (_) => verify( | ||
| () => onReadError.call(QrPlusReadError.unreadable), | ||
| ).called(1), | ||
| ); | ||
|
|
||
| blocTest<QrPlusReaderCubit, QrPlusReaderState>( | ||
| 'is not called ' | ||
| 'when the code decrypts successfully', | ||
| build: () => QrPlusReaderCubit( | ||
| mode: mode, | ||
| onData: onData.call, | ||
| onReadError: onReadError.call, | ||
| ntpRepository: ntpRepository, | ||
| ), | ||
| act: (cubit) { | ||
| final valid = QrPlusDataCrumb.authentic( | ||
| uid: 'uid', | ||
| data: 'data', | ||
| mode: mode, | ||
| timestamp: DateTime.utc(2026), | ||
| index: 0, | ||
| crumbs: 2, | ||
| ).toQrString(); | ||
|
|
||
| return cubit.onRawData(valid); | ||
| }, | ||
| verify: (_) => verifyNever(() => onReadError.call(any())), | ||
| ); | ||
|
|
||
| blocTest<QrPlusReaderCubit, QrPlusReaderState>( | ||
| 'does not throw ' | ||
| 'when no onReadError handler is provided', | ||
| build: () => QrPlusReaderCubit( | ||
| mode: mode, | ||
| onData: onData.call, | ||
| ntpRepository: ntpRepository, | ||
| ), | ||
| act: (cubit) => cubit.onRawData('not-a-qr-plus-code'), | ||
| ); | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a patch as 1.3.0 is broken? So 1.3.1?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the onError callback so I think 1.4.0 is more suitable. Probably should have been its own pr though.