1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use crate::{unwrap, PanicReason};
16 use np_ffi_core::common::DeallocateResult;
17 use np_ffi_core::deserialize::v0::*;
18 use np_ffi_core::deserialize::DecryptMetadataResult;
19 use np_ffi_core::utils::FfiEnum;
20 use np_ffi_core::v0::*;
21
22 /// Gets the tag of a `DeserializedV0Advertisement` tagged-union.
23 #[no_mangle]
np_ffi_DeserializedV0Advertisement_kind( result: DeserializedV0Advertisement, ) -> DeserializedV0AdvertisementKind24 pub extern "C" fn np_ffi_DeserializedV0Advertisement_kind(
25 result: DeserializedV0Advertisement,
26 ) -> DeserializedV0AdvertisementKind {
27 result.kind()
28 }
29
30 /// Casts a `DeserializedV0Advertisement` to the `Legible` variant, panicking in the
31 /// case where the passed value is of a different enum variant.
32 #[no_mangle]
np_ffi_DeserializedV0Advertisement_into_LEGIBLE( adv: DeserializedV0Advertisement, ) -> LegibleDeserializedV0Advertisement33 pub extern "C" fn np_ffi_DeserializedV0Advertisement_into_LEGIBLE(
34 adv: DeserializedV0Advertisement,
35 ) -> LegibleDeserializedV0Advertisement {
36 unwrap(adv.into_legible(), PanicReason::EnumCastFailed)
37 }
38
39 /// Gets the number of DEs in a legible deserialized advertisement.
40 /// Suitable as an iteration bound for `V0Payload#get_de`.
41 #[no_mangle]
np_ffi_LegibleDeserializedV0Advertisement_get_num_des( adv: LegibleDeserializedV0Advertisement, ) -> u842 pub extern "C" fn np_ffi_LegibleDeserializedV0Advertisement_get_num_des(
43 adv: LegibleDeserializedV0Advertisement,
44 ) -> u8 {
45 adv.num_des()
46 }
47
48 /// Gets just the data-element payload of a `LegibleDeserializedV0Advertisement`.
49 #[no_mangle]
np_ffi_LegibleDeserializedV0Advertisement_into_payload( adv: LegibleDeserializedV0Advertisement, ) -> V0Payload50 pub extern "C" fn np_ffi_LegibleDeserializedV0Advertisement_into_payload(
51 adv: LegibleDeserializedV0Advertisement,
52 ) -> V0Payload {
53 adv.payload()
54 }
55
56 /// Gets just the identity kind associated with a `LegibleDeserializedV0Advertisement`.
57 #[no_mangle]
np_ffi_LegibleDeserializedV0Advertisement_get_identity_kind( adv: LegibleDeserializedV0Advertisement, ) -> DeserializedV0IdentityKind58 pub extern "C" fn np_ffi_LegibleDeserializedV0Advertisement_get_identity_kind(
59 adv: LegibleDeserializedV0Advertisement,
60 ) -> DeserializedV0IdentityKind {
61 adv.identity_kind()
62 }
63
64 /// Deallocates any internal data of a `LegibleDeserializedV0Advertisement`
65 #[no_mangle]
np_ffi_deallocate_legible_v0_advertisement( adv: LegibleDeserializedV0Advertisement, ) -> DeallocateResult66 pub extern "C" fn np_ffi_deallocate_legible_v0_advertisement(
67 adv: LegibleDeserializedV0Advertisement,
68 ) -> DeallocateResult {
69 adv.deallocate()
70 }
71
72 /// Attempts to get the data-element with the given index in the passed v0 adv payload
73 #[no_mangle]
np_ffi_V0Payload_get_de(payload: V0Payload, index: u8) -> GetV0DEResult74 pub extern "C" fn np_ffi_V0Payload_get_de(payload: V0Payload, index: u8) -> GetV0DEResult {
75 payload.get_de(index)
76 }
77
78 /// Attempts to decrypt the metadata for the matched credential for this V0 payload (if any)
79 #[no_mangle]
np_ffi_V0Payload_decrypt_metadata(payload: V0Payload) -> DecryptMetadataResult80 pub extern "C" fn np_ffi_V0Payload_decrypt_metadata(payload: V0Payload) -> DecryptMetadataResult {
81 payload.decrypt_metadata()
82 }
83
84 /// Gets the identity details for this V0 payload, or returns an error if this payload does not have
85 /// any associated identity (public advertisement)
86 #[no_mangle]
np_ffi_V0Payload_get_identity_details( payload: V0Payload, ) -> GetV0IdentityDetailsResult87 pub extern "C" fn np_ffi_V0Payload_get_identity_details(
88 payload: V0Payload,
89 ) -> GetV0IdentityDetailsResult {
90 payload.get_identity_details()
91 }
92
93 /// Gets the tag of a `GetV0IdentityDetailsResult` tagged-union. On success the wrapped identity
94 /// details may be obtained via `GetV0IdentityDetailsResult#into_success`.
95 #[no_mangle]
np_ffi_GetV0IdentityDetailsResult_kind( result: GetV0IdentityDetailsResult, ) -> GetV0IdentityDetailsResultKind96 pub extern "C" fn np_ffi_GetV0IdentityDetailsResult_kind(
97 result: GetV0IdentityDetailsResult,
98 ) -> GetV0IdentityDetailsResultKind {
99 result.kind()
100 }
101
102 /// Casts a `GetV0IdentityDetailsResult` to the `Success` variant, panicking in the
103 /// case where the passed value is of a different enum variant.
104 #[no_mangle]
np_ffi_GetV0IdentityDetailsResult_into_SUCCESS( result: GetV0IdentityDetailsResult, ) -> DeserializedV0IdentityDetails105 pub extern "C" fn np_ffi_GetV0IdentityDetailsResult_into_SUCCESS(
106 result: GetV0IdentityDetailsResult,
107 ) -> DeserializedV0IdentityDetails {
108 unwrap(result.into_success(), PanicReason::EnumCastFailed)
109 }
110
111 /// Deallocates any internal data of a `V0Payload`
112 #[no_mangle]
np_ffi_deallocate_v0_payload(payload: V0Payload) -> DeallocateResult113 pub extern "C" fn np_ffi_deallocate_v0_payload(payload: V0Payload) -> DeallocateResult {
114 payload.deallocate_payload()
115 }
116
117 /// Gets the tag of a `GetV0DEResult` tagged-union.
118 #[no_mangle]
np_ffi_GetV0DEResult_kind(result: GetV0DEResult) -> GetV0DEResultKind119 pub extern "C" fn np_ffi_GetV0DEResult_kind(result: GetV0DEResult) -> GetV0DEResultKind {
120 result.kind()
121 }
122
123 /// Casts a `GetV0DEResult` to the `Success` variant, panicking in the
124 /// case where the passed value is of a different enum variant.
125 #[no_mangle]
np_ffi_GetV0DEResult_into_SUCCESS(result: GetV0DEResult) -> V0DataElement126 pub extern "C" fn np_ffi_GetV0DEResult_into_SUCCESS(result: GetV0DEResult) -> V0DataElement {
127 unwrap(result.into_success(), PanicReason::EnumCastFailed)
128 }
129