optee_utee/
identity.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::Uuid;
19use optee_utee_sys as raw;
20
21#[derive(Copy, Clone)]
22pub struct Identity {
23    raw: raw::TEE_Identity,
24}
25
26impl Identity {
27    pub fn login_type(&self) -> LoginType {
28        match self.raw.login {
29            raw::TEE_LOGIN_PUBLIC => LoginType::Public,
30            raw::TEE_LOGIN_USER => LoginType::User,
31            raw::TEE_LOGIN_GROUP => LoginType::Group,
32            raw::TEE_LOGIN_APPLICATION => LoginType::Application,
33            raw::TEE_LOGIN_APPLICATION_USER => LoginType::ApplicationUser,
34            raw::TEE_LOGIN_APPLICATION_GROUP => LoginType::ApplicationGroup,
35            raw::TEE_LOGIN_TRUSTED_APP => LoginType::TrustedApp,
36            _ => panic!("Invalid login type"),
37        }
38    }
39
40    pub fn uuid(&self) -> Uuid {
41        Uuid::from(self.raw.uuid)
42    }
43}
44
45impl From<raw::TEE_Identity> for Identity {
46    fn from(raw: raw::TEE_Identity) -> Self {
47        Self { raw }
48    }
49}
50
51#[derive(Copy, Clone, PartialEq, Eq, strum::Display)]
52#[repr(u32)]
53pub enum LoginType {
54    Public = raw::TEE_LOGIN_PUBLIC,
55    User = raw::TEE_LOGIN_USER,
56    Group = raw::TEE_LOGIN_GROUP,
57    Application = raw::TEE_LOGIN_APPLICATION,
58    ApplicationUser = raw::TEE_LOGIN_APPLICATION_USER,
59    ApplicationGroup = raw::TEE_LOGIN_APPLICATION_GROUP,
60    TrustedApp = raw::TEE_LOGIN_TRUSTED_APP,
61}