Skip to content

Commit

Permalink
address format comments and function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq committed Feb 6, 2025
1 parent 2b8acef commit 436d132
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const EParseError: u64 = 1;
/// Error that the attestation failed to be verified.
const EVerifyError: u64 = 2;
#[allow(unused_const)]
/// Error that the pcrs length is invalid.
const EInvalidPcrLength: u64 = 3;

/// Represents a PCR entry with an index and value.
public struct PCREntry has drop {
Expand All @@ -32,9 +30,8 @@ public struct NitroAttestationDocument has drop {
timestamp: u64,
/// The digest function used for calculating the register values.
digest: vector<u8>,
/// The map of all locked PCRs at the moment the attestation document was generated.
/// The array contains PCR0, PCR1, PCR2, PCR3, PCR4, PCR8. See more
/// <https://docs.aws.amazon.com/enclaves/latest/user/set-up-attestation.html#where>.
/// A list of PCREntry containing the index and the PCR bytes.
/// <https://docs.aws.amazon.com/enclaves/latest/user/set-up-attestation.html#where>.
pcrs: vector<PCREntry>,
/// An optional DER-encoded key the attestation, consumer can use to encrypt data with.
public_key: Option<vector<u8>>,
Expand All @@ -45,22 +42,16 @@ public struct NitroAttestationDocument has drop {
nonce: Option<vector<u8>>,
}

/// Internal native function
native fun verify_nitro_attestation_internal(
attestation: &vector<u8>,
current_timestamp: u64
): NitroAttestationDocument;

/// @param attestation: attesttaion documents bytes data.
/// @param clock: the clock object.
///
/// Returns parsed NitroAttestationDocument after verifying the attestation, may abort with
/// errors described above.
public fun verify_nitro_attestation(
/// Returns the parsed NitroAttestationDocument after verifying the attestation,
/// may abort with errors described above.
entry fun load_nitro_attestation(
attestation: &vector<u8>,
clock: &Clock
): NitroAttestationDocument {
verify_nitro_attestation_internal(attestation, clock::timestamp_ms(clock))
load_nitro_attestation_internal(attestation, clock::timestamp_ms(clock))
}

public fun module_id(attestation: &NitroAttestationDocument): &vector<u8> {
Expand All @@ -75,8 +66,8 @@ public fun digest(attestation: &NitroAttestationDocument): &vector<u8> {
&attestation.digest
}

/// Returns a list of mapping from index to the pcr itself. Currently AWS supports
///PCR0, PCR1, PCR2, PCR3, PCR4, PCR8.
/// Returns a list of mapping PCREntry containg the index and the PCR bytes.
/// Currently AWS supports supports PCR0, PCR1, PCR2, PCR3, PCR4, PCR8.
public fun pcrs(attestation: &NitroAttestationDocument): &vector<PCREntry> {
&attestation.pcrs
}
Expand All @@ -100,3 +91,9 @@ public fun index(entry: &PCREntry): u8 {
public fun value(entry: &PCREntry): &vector<u8> {
&entry.value
}

/// Internal native function
native fun load_nitro_attestation_internal(
attestation: &vector<u8>,
current_timestamp: u64,
): NitroAttestationDocument;
Loading

0 comments on commit 436d132

Please sign in to comment.