@@ -282,8 +282,110 @@ impl Context {
282282
283283 /// Generate a quote on the selected PCRs
284284 ///
285+ /// # Arguments
286+ /// * `signing_key_handle` - Handle of key that will perform signature.
287+ /// * `qualifying_data` - Data supplied by the caller.
288+ /// * `signing_scheme` - Signing scheme to use if the scheme for signing_key_handle is the null scheme.
289+ /// * `pcr_selection_list` - The PCR set to quote.
290+ ///
285291 /// # Errors
286- /// * if the qualifying data provided is too long, a `WrongParamSize` wrapper error will be returned
292+ /// * if the qualifying data provided is too long, a `WrongParamSize` wrapper error will be returned.
293+ ///
294+ /// # Examples
295+ ///
296+ /// ```rust
297+ /// # use tss_esapi::{Context, TctiNameConf};
298+ /// use std::convert::TryFrom;
299+ /// # use tss_esapi::{
300+ /// # handles::KeyHandle,
301+ /// # interface_types::{
302+ /// # algorithm::{RsaSchemeAlgorithm, SignatureSchemeAlgorithm},
303+ /// # key_bits::RsaKeyBits,
304+ /// # reserved_handles::Hierarchy,
305+ /// # },
306+ /// # structures::{
307+ /// # AttestInfo, RsaExponent, RsaScheme, Signature,
308+ /// # },
309+ /// # utils::{create_unrestricted_signing_rsa_public, create_restricted_decryption_rsa_public},
310+ /// # };
311+ /// use tss_esapi::{
312+ /// interface_types::{
313+ /// algorithm::HashingAlgorithm,
314+ /// session_handles::AuthSession,
315+ /// },
316+ /// structures::{
317+ /// Data, PcrSelectionListBuilder, PcrSlot, SignatureScheme,
318+ /// },
319+ /// };
320+ ///
321+ /// # let mut context =
322+ /// # Context::new(
323+ /// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
324+ /// # ).expect("Failed to create Context");
325+ /// let qualifying_data = Data::try_from(vec![0xff; 16])
326+ /// .expect("It should be possible to create qualifying data from bytes.");
327+ /// # let signing_key_pub = create_unrestricted_signing_rsa_public(
328+ /// # RsaScheme::create(RsaSchemeAlgorithm::RsaSsa, Some(HashingAlgorithm::Sha256))
329+ /// # .expect("Failed to create RSA scheme"),
330+ /// # RsaKeyBits::Rsa2048,
331+ /// # RsaExponent::default(),
332+ /// # )
333+ /// # .expect("Failed to create an unrestricted signing rsa public structure");
334+ /// # let sign_key_handle = context
335+ /// # .execute_with_nullauth_session(|ctx| {
336+ /// # ctx.create_primary(Hierarchy::Owner, signing_key_pub, None, None, None, None)
337+ /// # })
338+ /// # .unwrap()
339+ /// # .key_handle;
340+ ///
341+ /// // Quote PCR 0, 1, 2
342+ /// let pcr_selection_list = PcrSelectionListBuilder::new()
343+ /// .with_selection(HashingAlgorithm::Sha256, &[PcrSlot::Slot0, PcrSlot::Slot1, PcrSlot::Slot2])
344+ /// .build()
345+ /// .expect("It should be possible to create PCR selection list with valid values.");
346+ ///
347+ /// let (attest, signature) = context
348+ /// .execute_with_sessions(
349+ /// (
350+ /// Some(AuthSession::Password),
351+ /// None,
352+ /// None,
353+ /// ),
354+ /// |ctx| {
355+ /// ctx.quote(
356+ /// sign_key_handle,
357+ /// qualifying_data,
358+ /// SignatureScheme::Null,
359+ /// pcr_selection_list.clone(),
360+ /// )
361+ /// },
362+ /// )
363+ /// .expect("Failed to get quote");
364+ /// # match signature {
365+ /// # Signature::RsaSsa(signature) => {
366+ /// # assert_eq!(signature.hashing_algorithm(), HashingAlgorithm::Sha256);
367+ /// # }
368+ /// # _ => {
369+ /// # panic!("Received the wrong signature from the call to `quote`.");
370+ /// # }
371+ /// # }
372+ /// # match attest.attested() {
373+ /// # AttestInfo::Quote { info } => {
374+ /// # assert!(
375+ /// # !info.pcr_digest().is_empty(),
376+ /// # "Digest in QuoteInfo is empty"
377+ /// # );
378+ /// # assert_eq!(
379+ /// # &pcr_selection_list,
380+ /// # info.pcr_selection(),
381+ /// # "QuoteInfo selection list did not match the input selection list"
382+ /// # );
383+ /// # }
384+ /// # _ => {
385+ /// # panic!("Attested did not contain the expected variant.")
386+ /// # }
387+ /// # }
388+ /// ```
287389 pub fn quote (
288390 & mut self ,
289391 signing_key_handle : KeyHandle ,
0 commit comments