Skip to content

Commit 2be05a1

Browse files
authored
Merge pull request #101 from linux-credentials/tag-value-serialization
Serialization and error handling improvements
2 parents d868bdd + 786ad62 commit 2be05a1

File tree

14 files changed

+893
-634
lines changed

14 files changed

+893
-634
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### UI Controller API
66

77
- Renamed `InitiateEventStream()` to `Subscribe()`
8+
- Serialize `BackgroundEvent`, `HybridState`, `UsbState` as tag-value structs
89

910
# [0.1.0] - 2025-08-14
1011

credentialsd-common/meson.build

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,17 @@
11
# Currently, we're not building this with meson and just letting cargo path dependencies for the other projects build this lib.
22
# Not efficient, since the UI and daemon projects will build it separately, but leaving it this way for now.
33

4-
# common_lib_name = 'xyzii-credman-portal-gtk'
5-
# base_id = 'xyz.iinuwa.CredentialManagerUi'
6-
#
7-
# cargo = find_program('cargo', required: true)
8-
#
9-
# version = meson.project_version()
10-
#
11-
# if get_option('profile') == 'development'
12-
# profile = 'Devel'
13-
# vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: false).stdout().strip()
14-
# if vcs_tag == ''
15-
# version_suffix = '-devel'
16-
# else
17-
# version_suffix = '-@0@'.format(vcs_tag)
18-
# endif
19-
# application_id = '@0@.@1@'.format(base_id, profile)
20-
# else
21-
# profile = ''
22-
# version_suffix = ''
23-
# application_id = base_id
24-
# endif
25-
#
26-
# meson.add_dist_script(
27-
# meson.project_source_root() / 'build-aux/dist-vendor.sh',
28-
# meson.project_build_root() / 'meson-dist' / common_lib_name + '-' + version,
29-
# meson.project_source_root(),
30-
# )
31-
#
32-
# cargo_options = [
33-
# '--manifest-path', meson.project_source_root() / meson.current_source_dir() / 'Cargo.toml',
34-
# ]
35-
# cargo_options += [
36-
# '--target-dir', meson.project_build_root() / meson.current_build_dir() / 'target',
37-
# ]
38-
# if get_option('cargo_offline') == true
39-
# cargo_options += ['--offline']
40-
# endif
41-
#
42-
# subdir('src')
4+
common_lib_name = 'credentialsd-common'
5+
cargo = find_program('cargo', required: true)
6+
7+
cargo_options = [
8+
'--manifest-path', meson.project_source_root() / meson.current_source_dir() / 'Cargo.toml',
9+
]
10+
cargo_options += [
11+
'--target-dir', meson.project_build_root() / meson.current_build_dir() / 'target',
12+
]
13+
if get_option('cargo_offline') == true
14+
cargo_options += ['--offline']
15+
endif
16+
17+
subdir('src')

credentialsd-common/src/meson.build

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Currently, we're not building this with meson and just letting cargo path dependencies for the other projects build this lib.
22
# Not efficient, since the UI and daemon projects will build it separately, but leaving it this way for now.
33

4-
# if get_option('profile') == 'default'
5-
# cargo_options += ['--release']
6-
# rust_target = 'release'
7-
# message('Building in release mode')
8-
# else
9-
# rust_target = 'debug'
10-
# message('Building in debug mode')
11-
# endif
12-
#
13-
# cargo_env = ['CARGO_HOME=' + cargo_home]
4+
if get_option('profile') == 'default'
5+
cargo_options += ['--release']
6+
rust_target = 'release'
7+
message('Building in release mode')
8+
else
9+
rust_target = 'debug'
10+
message('Building in debug mode')
11+
endif
12+
13+
cargo_env = ['CARGO_HOME=' + cargo_home]
1414
#
1515
# custom_target(
1616
# 'cargo-build',
@@ -31,4 +31,17 @@
3131
# common_lib_name / 'src' / rust_target / common_lib_name,
3232
# '@OUTPUT@',
3333
# ],
34-
# )
34+
# )
35+
test(
36+
'credentialsd-common cargo-unit-tests',
37+
cargo,
38+
env: [cargo_env],
39+
args: [
40+
'test',
41+
'--lib',
42+
'--no-fail-fast', cargo_options,
43+
'--',
44+
'--nocapture',
45+
],
46+
protocol: 'exitcode',
47+
)

credentialsd-common/src/model.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub enum UsbState {
262262
Failed(Error),
263263
}
264264

265-
#[derive(Debug)]
265+
#[derive(Clone, Debug)]
266266
pub enum BackgroundEvent {
267267
UsbStateChanged(UsbState),
268268
HybridQrStateChanged(HybridState),
@@ -301,6 +301,7 @@ impl Display for Error {
301301
}
302302
}
303303

304+
#[derive(Debug)]
304305
pub enum WebAuthnError {
305306
/// The ceremony was cancelled by an AbortController. See § 5.6 Abort
306307
/// Operations with AbortSignal and § 1.3.4 Aborting Authentication
@@ -337,3 +338,19 @@ pub enum WebAuthnError {
337338
/// the value of `user.id` was empty or was longer than 64 bytes.
338339
TypeError,
339340
}
341+
342+
impl std::error::Error for WebAuthnError {}
343+
344+
impl Display for WebAuthnError {
345+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
346+
f.write_str(match self {
347+
WebAuthnError::AbortError => "Operation was aborted by client.",
348+
WebAuthnError::ConstraintError => "Resident key or user verification requirement was not able to be met.",
349+
WebAuthnError::InvalidStateError => "A user consented to create a new credential after trying to use an authenticator with a previously registered credential.",
350+
WebAuthnError::NotSupportedError => "Operation parameters are not supported.",
351+
WebAuthnError::SecurityError => "Validation of the client context for given RP ID failed.",
352+
WebAuthnError::NotAllowedError => "An unspecified error occurred, and the operation is not allowed to continue.",
353+
WebAuthnError::TypeError => "Invalid parameters specified.",
354+
})
355+
}
356+
}

0 commit comments

Comments
 (0)