1 //! Defines the context type for a session handling hwtrust data structures. 2 3 use crate::dice::ProfileVersion; 4 use std::ops::RangeInclusive; 5 6 /// The context for a session handling hwtrust data structures. 7 #[derive(Default, Debug)] 8 pub struct Session { 9 /// Options that control the behaviour during this session. 10 pub options: Options, 11 } 12 13 /// Options that control the behaviour of a session. 14 #[derive(Default, Debug)] 15 pub struct Options { 16 /// The range of supported Android Profile for DICE versions. 17 pub dice_profile_range: DiceProfileRange, 18 } 19 20 /// An inclusive range of Android Profile for DICE versions. 21 #[derive(Clone, Debug, PartialEq, Eq)] 22 pub struct DiceProfileRange(RangeInclusive<ProfileVersion>); 23 24 impl DiceProfileRange { 25 /// Creates a new inclusive range of Android Profile for DICE versions. new(start: ProfileVersion, end: ProfileVersion) -> Self26 pub fn new(start: ProfileVersion, end: ProfileVersion) -> Self { 27 Self(RangeInclusive::new(start, end)) 28 } 29 30 /// Returns `true` if `version` is contained in the range. contains(&self, version: ProfileVersion) -> bool31 pub fn contains(&self, version: ProfileVersion) -> bool { 32 self.0.contains(&version) 33 } 34 35 /// Returns the lower bound of the range. start(&self) -> ProfileVersion36 pub fn start(&self) -> ProfileVersion { 37 *self.0.start() 38 } 39 40 /// Returns the upper bound of the range. end(&self) -> ProfileVersion41 pub fn end(&self) -> ProfileVersion { 42 *self.0.end() 43 } 44 } 45 46 impl Default for DiceProfileRange { default() -> Self47 fn default() -> Self { 48 Self::new(ProfileVersion::Android14, ProfileVersion::Android16) 49 } 50 } 51 52 impl Options { 53 /// The options use by VSR 13. vsr13() -> Self54 pub fn vsr13() -> Self { 55 Self { 56 dice_profile_range: DiceProfileRange::new( 57 ProfileVersion::Android13, 58 ProfileVersion::Android13, 59 ), 60 } 61 } 62 63 /// The options use by VSR 14. vsr14() -> Self64 pub fn vsr14() -> Self { 65 Self { 66 dice_profile_range: DiceProfileRange::new( 67 ProfileVersion::Android14, 68 ProfileVersion::Android14, 69 ), 70 } 71 } 72 73 /// The options use by VSR 15. vsr15() -> Self74 pub fn vsr15() -> Self { 75 Self { 76 dice_profile_range: DiceProfileRange::new( 77 ProfileVersion::Android14, 78 ProfileVersion::Android15, 79 ), 80 } 81 } 82 83 /// The options use by VSR 16. vsr16() -> Self84 pub fn vsr16() -> Self { 85 Self { 86 dice_profile_range: DiceProfileRange::new( 87 ProfileVersion::Android14, 88 ProfileVersion::Android16, 89 ), 90 } 91 } 92 } 93