-
Notifications
You must be signed in to change notification settings - Fork 19
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
WinScard and WinScardContex traits and their implementations #203
Merged
CBenoit
merged 14 commits into
winscard-rs-impl
from
feature/winscard-context-and-traits-impl
Jan 31, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
60d1738
feat(winscard): add WinScard and WinScardContex trait. add helper str…
TheBestTvarynka 177ecbc
feat(winscard): implement WinScardContext trait for the ScardContext
TheBestTvarynka 203d8eb
feat(winscard): add doc comments in the winscard module. small refact…
TheBestTvarynka 9332017
feat(winscard): add different From implementations for Icon struct
TheBestTvarynka d6d6e32
refactor(winscard): replace String with Cow
TheBestTvarynka 97491a3
refactor(winscard): rename Result -> WinScardResult
TheBestTvarynka 53c58b0
feat(winscard): implement WinScard::state for SmartCard. add more doc…
TheBestTvarynka 669a563
feat(winscard): implement WinScard trait for SmartCard
TheBestTvarynka 31489c0
fix(winscard): comment
TheBestTvarynka 602dec2
fix(winscard): atr string
TheBestTvarynka 2c409aa
feat(winscard): implement smart card creation from scard context
TheBestTvarynka 956739a
featr(winscard): replace raw pk with parsed one
TheBestTvarynka da4b0cf
refac(winscard): format code, fix clippy errors, fix tests;
TheBestTvarynka 74055f8
fix(sspi): smartcard: emulated scard creation and tests;
TheBestTvarynka 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 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 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 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,87 @@ | ||
use alloc::borrow::{Cow, ToOwned}; | ||
use alloc::boxed::Box; | ||
use alloc::format; | ||
use alloc::vec::Vec; | ||
|
||
use picky::key::PrivateKey; | ||
|
||
use crate::scard::SmartCard; | ||
use crate::winscard::{DeviceTypeId, Icon, Protocol, ShareMode, WinScard, WinScardContext}; | ||
use crate::{Error, ErrorKind, WinScardResult}; | ||
|
||
/// Describes a smart card reader. | ||
#[derive(Debug, Clone)] | ||
pub struct Reader<'a> { | ||
pub name: Cow<'a, str>, | ||
pub icon: Icon<'a>, | ||
pub device_type_id: DeviceTypeId, | ||
} | ||
|
||
/// Describes smart card info used for the smart card creation | ||
pub struct SmartCardInfo<'a> { | ||
pub pin: Vec<u8>, | ||
pub auth_cert_der: Vec<u8>, | ||
pub auth_pk: PrivateKey, | ||
pub reader: Reader<'a>, | ||
} | ||
|
||
/// Represents the resource manager context (the scope). | ||
pub struct ScardContext<'a> { | ||
smart_cards_info: Vec<SmartCardInfo<'a>>, | ||
} | ||
|
||
impl<'a> ScardContext<'a> { | ||
/// Creates a new smart card based on the list of smart card readers | ||
pub fn new(smart_cards_info: Vec<SmartCardInfo<'a>>) -> Self { | ||
Self { smart_cards_info } | ||
} | ||
} | ||
|
||
impl<'a> WinScardContext for ScardContext<'a> { | ||
fn connect( | ||
&self, | ||
reader_name: &str, | ||
_share_mode: ShareMode, | ||
_protocol: Option<Protocol>, | ||
) -> WinScardResult<Box<dyn WinScard>> { | ||
let smart_card_info = self | ||
.smart_cards_info | ||
.iter() | ||
.find(|card_info| card_info.reader.name == reader_name) | ||
.ok_or_else(|| Error::new(ErrorKind::UnknownReader, format!("reader {} not found", reader_name)))?; | ||
|
||
Ok(Box::new(SmartCard::new( | ||
Cow::Owned(reader_name.to_owned()), | ||
smart_card_info.pin.clone(), | ||
smart_card_info.auth_cert_der.clone(), | ||
smart_card_info.auth_pk.clone(), | ||
)?)) | ||
} | ||
|
||
fn list_readers(&self) -> Vec<Cow<str>> { | ||
self.smart_cards_info | ||
.iter() | ||
.map(|card_info| card_info.reader.name.clone()) | ||
.collect() | ||
} | ||
|
||
fn device_type_id(&self, reader_name: &str) -> WinScardResult<DeviceTypeId> { | ||
self.smart_cards_info | ||
.iter() | ||
.find(|card_info| card_info.reader.name == reader_name) | ||
.ok_or_else(|| Error::new(ErrorKind::UnknownReader, format!("reader {} not found", reader_name))) | ||
.map(|card_info| card_info.reader.device_type_id) | ||
} | ||
|
||
fn reader_icon(&self, reader_name: &str) -> WinScardResult<Icon> { | ||
self.smart_cards_info | ||
.iter() | ||
.find(|card_info| card_info.reader.name == reader_name) | ||
.ok_or_else(|| Error::new(ErrorKind::UnknownReader, format!("reader {} not found", reader_name))) | ||
.map(|card_info| card_info.reader.icon.clone()) | ||
} | ||
|
||
fn is_valid(&self) -> bool { | ||
!self.smart_cards_info.is_empty() | ||
} | ||
} |
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.
Just noticed that the folder is called
winscard-rs
instead ofwinscard
. Do you think you could change this in another PR?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.
yes, I can change it