ledger_transport/lib.rs
1/*******************************************************************************
2* (c) 2022 Zondax AG
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15********************************************************************************/
16//! Generic APDU transport library for Ledger Nano S/X apps
17
18#![deny(trivial_casts, trivial_numeric_casts)]
19#![deny(unused_import_braces, unused_qualifications)]
20#![deny(missing_docs)]
21
22use std::ops::Deref;
23
24pub use async_trait::async_trait;
25pub use ledger_apdu::{APDUAnswer, APDUCommand, APDUErrorCode};
26
27/// Use to talk to the ledger device
28#[async_trait]
29pub trait Exchange {
30 /// Error defined by Transport used
31 type Error;
32
33 /// The concrete type containing the APDUAnswer
34 type AnswerType: Deref<Target = [u8]> + Send;
35
36 /// Send a command with the given transport and retrieve an answer or a transport error
37 async fn exchange<I>(
38 &self,
39 command: &APDUCommand<I>,
40 ) -> Result<APDUAnswer<Self::AnswerType>, Self::Error>
41 where
42 I: Deref<Target = [u8]> + Send + Sync;
43}