1use std::fmt::Display;
2use std::ops::Deref;
3
4use crate::{ffi, init_library, IDAError};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct LicenseId([u8; 6]);
8
9impl Display for LicenseId {
10 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11 let id = self.0;
12 write!(
13 f,
14 "{:02X}-{:02X}{:02X}-{:02X}{:02X}-{:02X}",
15 id[0], id[1], id[2], id[3], id[4], id[5]
16 )
17 }
18}
19
20impl AsRef<[u8]> for LicenseId {
21 fn as_ref(&self) -> &[u8] {
22 &self.0
23 }
24}
25
26impl Deref for LicenseId {
27 type Target = [u8];
28
29 fn deref(&self) -> &Self::Target {
30 &self.0
31 }
32}
33
34impl From<LicenseId> for [u8; 6] {
35 fn from(value: LicenseId) -> Self {
36 value.0
37 }
38}
39
40pub fn is_valid_license() -> bool {
41 init_library();
42 ffi::ida::is_license_valid()
43}
44
45pub fn license_id() -> Result<LicenseId, IDAError> {
46 init_library();
47 Ok(LicenseId(ffi::ida::license_id()?))
48}