Skip to content

Commit 8184b7d

Browse files
committed
Test cases for functions 'write_authorize_nv' and 'get_poll_handles()' have been added.
1 parent 9554fdd commit 8184b7d

8 files changed

Lines changed: 106 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7+
## [0.13.0] - 2026-03-19
8+
9+
### Added
10+
11+
- Test cases for functions `write_authorize_nv` and `get_poll_handles()` have been added.
12+
- New error code `InternalError::NotImplemented` has been added.
13+
14+
### Changed
15+
16+
- Docker images used for testing/building have been updated to the latest version.
17+
718
## [0.12.2] - 2026-03-03
819

920
### Changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tss2-fapi-rs"
3-
version = "0.12.2"
3+
version = "0.13.0"
44
edition = "2024"
55
rust-version = "1.85"
66
description = "Provides a Rust interface to the TSS2.0 Feature API (FAPI)"

src/context.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ const ERR_INVALID_ARGUMENTS: ErrorCode = ErrorCode::InternalError(InternalError:
2424

2525
/* Opaque ContextBlob type */
2626
#[derive(Debug)]
27+
#[non_exhaustive]
2728
pub struct TctiOpaqueContextBlob(pub *mut c_void);
2829

30+
/* Opaque ContextBlob type */
31+
#[derive(Debug)]
32+
#[non_exhaustive]
33+
pub struct FapiPollHandle(pub *mut c_void);
34+
2935
/// Wraps the native `FAPI_CONTEXT` and exposes the related FAPI functions.
3036
///
3137
/// Each FAPI context represents a logically independent connection to the TPM. It stores meta data information about object in order to calculate session auths and similar things.
@@ -928,8 +934,8 @@ impl FapiContext {
928934
/// This functions is a stub. Currently, `Fapi_GetPollHandles()` is **not** implemented in the Rust wrapper library!
929935
///
930936
/// </div>
931-
pub fn get_poll_handles(&mut self) -> Result<Vec<()>, ErrorCode> {
932-
todo!("Not implemented yet.");
937+
pub fn get_poll_handles(&mut self) -> Result<Vec<FapiPollHandle>, ErrorCode> {
938+
Err(ErrorCode::InternalError(InternalError::NotImplemented))
933939
}
934940

935941
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub enum Tpm2Warning {
217217
pub enum InternalError {
218218
NoResultData,
219219
InvalidArguments,
220+
NotImplemented,
220221
}
221222

222223
impl ErrorCode {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
//!
8989
//! ```toml
9090
//! [dependencies]
91-
//! tss2-fapi-rs = "0.12.2"
91+
//! tss2-fapi-rs = "0.13.0"
9292
//! ```
9393
//!
9494
//! **Note:** Please also consider the [prerequisites](#prerequisites) that are required to use the `tss2-fapi-rs` library!

tests/09_policy_test.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::{fs, path::Path};
2424
use tss2_fapi_rs::{FapiCallbacks, FapiContext, ImportData, KeyFlags, json::JsonValue};
2525

2626
const KEY_FLAGS_SIGN: &[KeyFlags] = &[KeyFlags::NoDA, KeyFlags::Sign];
27+
const POLICY_NV_AUTH_SIZE: usize = 34usize;
2728

2829
// ==========================================================================
2930
// Test cases
@@ -44,7 +45,6 @@ fn test_policy_signed_rsa() {
4445
let mut rng = ChaChaRng::from_seed(create_seed(i));
4546

4647
// Create FAPI context
47-
4848
let mut context = match FapiContext::new() {
4949
Ok(fpai_ctx) => fpai_ctx,
5050
Err(error) => panic!("Failed to create context: {:?}", error),
@@ -255,6 +255,49 @@ fn test_policy_action() {
255255
});
256256
}
257257

258+
/// Test the `write_authorize_nv()` function to write a policy digest to an NV index.
259+
#[test]
260+
#[serial]
261+
#[named]
262+
fn test_write_authorize_nv() {
263+
let configuration = TestConfiguration::with_finalizer(|| my_tpm_finalizer(PASSWORD));
264+
265+
repeat_test!(|i| {
266+
let nv_path = &format!("nv/Owner/pol_digest{}", i);
267+
let pol_name = &format!("/policy/pol_signed_rsa{}", i);
268+
269+
// Create FAPI context
270+
let mut context = match FapiContext::new() {
271+
Ok(fpai_ctx) => fpai_ctx,
272+
Err(error) => panic!("Failed to create context: {:?}", error),
273+
};
274+
275+
// Read policy from file
276+
let policy_json = read_policy(configuration.data_path(), "pol_signed_rsa").expect("Failed to read policy!");
277+
278+
// Initialize TPM, if not already initialized
279+
tpm_initialize!(context, PASSWORD, MyCallbacks::new(PASSWORD, None));
280+
281+
// Import policy
282+
match context.import(pol_name, ImportData::from_json(&policy_json).unwrap()) {
283+
Ok(_) => debug!("Policy imported."),
284+
Err(error) => panic!("Failed to import policy: {:?}", error),
285+
};
286+
287+
// Create NV index, if not already created
288+
match context.create_nv(nv_path, Some(&[tss2_fapi_rs::NvFlags::NoDA]), POLICY_NV_AUTH_SIZE, None, None) {
289+
Ok(_) => debug!("NV index created."),
290+
Err(error) => panic!("NV index creation has failed: {:?}", error),
291+
}
292+
293+
// Write the policy digest to NV index
294+
match context.write_authorize_nv(nv_path, pol_name) {
295+
Ok(_) => debug!("Policy digest has been written to NV index."),
296+
Err(error) => panic!("Writing the policy digest failed: {:?}", error),
297+
}
298+
});
299+
}
300+
258301
// ==========================================================================
259302
// Helper functions
260303
// ==========================================================================

tests/20_get_poll_handles_test.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
/***********************************************************************************************
3+
* Copyright 2024-2026 Fraunhofer SIT, sponsored by the ELISA and ProSeCA research projects.
4+
* All rights reserved.
5+
**********************************************************************************************/
6+
7+
pub mod common;
8+
9+
use common::{callback::MyCallbacks, param::PASSWORD, setup::TestConfiguration, utils::my_tpm_finalizer};
10+
use function_name::named;
11+
use serial_test::serial;
12+
use tss2_fapi_rs::{ErrorCode, FapiContext, InternalError};
13+
14+
// ==========================================================================
15+
// Test cases
16+
// ==========================================================================
17+
18+
/// Test the `get_poll_handles()` function (which is **not** currently implemented)
19+
#[test]
20+
#[serial]
21+
#[named]
22+
fn test_get_poll_handles() {
23+
let _configuration = TestConfiguration::with_finalizer(|| my_tpm_finalizer(PASSWORD));
24+
25+
repeat_test!(|_i| {
26+
// Create FAPI context
27+
let mut context = match FapiContext::new() {
28+
Ok(fpai_ctx) => fpai_ctx,
29+
Err(error) => panic!("Failed to create context: {:?}", error),
30+
};
31+
32+
// Initialize TPM, if not already initialized
33+
tpm_initialize!(context, PASSWORD, MyCallbacks::new(PASSWORD, None));
34+
35+
// Try to acquire the poll handles (this is expected to fail!)
36+
let result = context.get_poll_handles();
37+
assert!(matches!(result, Err(ErrorCode::InternalError(InternalError::NotImplemented))));
38+
});
39+
}

0 commit comments

Comments
 (0)