### Initialize SignatureTemplate Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/layout/struct.SignatureTemplate.html Example showing how to instantiate a SignatureTemplate with custom lines and layout properties. ```rust use underskrift::visual::layout::{SignatureTemplate, SignatureLayout}; use std::sync::Arc; let template = SignatureTemplate::new(vec![ "Digitally signed by ##SIGNER_NAME##".to_string(), "Date: ##DATE##".to_string(), "Reason: ##REASON##".to_string(), "Location: ##LOCATION##".to_string(), ]) .font_size(9.0) .padding(5.0); let layout = SignatureLayout::Custom(Arc::new(template)); ``` -------------------------------- ### Initialize PkixPdfSignaturePolicy Source: https://docs.rs/underskrift/0.1.4/underskrift/policy/pkix/struct.PkixPdfSignaturePolicy.html Example showing how to instantiate and configure a PkixPdfSignaturePolicy using the builder pattern. ```rust use underskrift::policy::PkixPdfSignaturePolicy; use std::time::Duration; let policy = PkixPdfSignaturePolicy::new() .grace_period(Duration::from_secs(48 * 3600)) // 48 hours .require_revocation_check(true); ``` -------------------------------- ### Initialize BasicPdfSignaturePolicy Source: https://docs.rs/underskrift/0.1.4/underskrift/policy/basic/struct.BasicPdfSignaturePolicy.html Example showing how to instantiate the policy for use with a SignatureVerifier. ```rust use underskrift::policy::BasicPdfSignaturePolicy; let policy = BasicPdfSignaturePolicy::new(); // Use with SignatureVerifier: // let verifier = SignatureVerifier::new(&trust_set).policy(Box::new(policy)); ``` -------------------------------- ### Initialize Revocation Check Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/revocation/index.html Demonstrates the setup of RevocationConfig and clients for OCSP and CRL before performing a revocation check. ```rust use tsp_ltv::ltv::revocation::{RevocationConfig, check_certificate_revocation}; use tsp_ltv::ltv::{OcspClient, CrlClient}; let config = RevocationConfig::default(); let ocsp = OcspClient::new(); let crl = CrlClient::new(); // let status = check_certificate_revocation(&cert, &issuer, &config, &crl, &ocsp, None).await; ``` -------------------------------- ### Extract Authentication Contexts Source: https://docs.rs/underskrift/0.1.4/underskrift/saci/index.html Example demonstrating how to extract and iterate over authentication contexts from an X.509 certificate. ```rust use underskrift::saci; use x509_cert::Certificate; use der::Decode; let contexts = saci::extract_authn_contexts(cert)?; for ctx in &contexts { if let Some(info) = &ctx.auth_context_info { println!("IdP: {}", info.identity_provider); println!("LoA: {}", info.authn_context_class_ref); } if let Some(attrs) = &ctx.id_attributes { for mapping in &attrs.mappings { println!("{}: {} = {:?}", mapping.mapping_type, mapping.reference, mapping.attribute.values); } } } ``` -------------------------------- ### Constructing RevocationConfig Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/revocation/struct.RevocationConfig.html Example of using struct-update syntax to override specific fields while maintaining default values for others. ```rust let config = RevocationConfig { require_revocation_check: false, ..RevocationConfig::default() }; ``` -------------------------------- ### Initialize TrustStoreSet Source: https://docs.rs/underskrift/0.1.4/underskrift/trust/struct.TrustStoreSet.html Demonstrates creating a new TrustStoreSet and configuring signature and timestamp authority stores from PEM files. ```rust use tsp_ltv::trust::{TrustStore, TrustStoreSet}; let stores = TrustStoreSet::new() .with_sig_store(TrustStore::from_pem_file("ca-bundle.pem")?) .with_tsa_store(TrustStore::from_pem_file("tsa-roots.pem")?); ``` -------------------------------- ### Get embedded font ascent Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/font/fn.embedded_ascent_1000.html Returns the ascent of an embedded font in 1/1000 units. ```rust pub fn embedded_ascent_1000(info: &EmbeddedFontInfo) -> i16 ``` -------------------------------- ### OcspClient::new Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/struct.OcspClient.html Creates a new instance of the OcspClient with default settings. ```APIDOC ## pub fn new() -> OcspClient ### Description Creates a new OCSP client with default settings. ### Returns - **OcspClient** - A new instance of the client. ``` -------------------------------- ### Get digest algorithm URI for JWS Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/algo/fn.digest_uri_for_jws.html Retrieves the URI associated with a specific JWS algorithm string. ```rust pub fn digest_uri_for_jws(jws_algo: &str) -> Result<&'static str, SvtError> ``` -------------------------------- ### ChainBuilder::new Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/chain/struct.ChainBuilder.html Creates a new instance of ChainBuilder with default settings. ```APIDOC ### Method `pub fn new() -> ChainBuilder` ### Description Initializes a new ChainBuilder instance with default configuration. ``` -------------------------------- ### Initialize TrustStore and TrustStoreSet Source: https://docs.rs/underskrift/0.1.4/underskrift/trust/index.html Demonstrates loading trust anchors from PEM files or directories and organizing them into a typed TrustStoreSet for different validation purposes. ```rust use tsp_ltv::trust::{TrustStore, TrustStoreSet}; // Load a trust store from a PEM file let sig_store = TrustStore::from_pem_file("ca-certs.pem")?; // Or from a directory of PEM files let tsa_store = TrustStore::from_pem_directory("/etc/ssl/certs")?; // Combine into a typed set let stores = TrustStoreSet::new() .with_sig_store(sig_store) .with_tsa_store(tsa_store); ``` -------------------------------- ### Get Digest Algorithm URI Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/issuer/struct.SvtIssuer.html Retrieves the digest algorithm URI corresponding to the issuer's configured JWS algorithm. ```rust pub fn digest_algo_uri(&self) -> &'static str ``` -------------------------------- ### Configure a SignatureVerifier with a custom policy Source: https://docs.rs/underskrift/0.1.4/underskrift/verify/struct.SignatureVerifier.html Demonstrates initializing a SignatureVerifier with a TrustStoreSet and applying a BasicPdfSignaturePolicy. ```rust use underskrift::verify::SignatureVerifier; use underskrift::policy::BasicPdfSignaturePolicy; use underskrift::trust::TrustStoreSet; let trust_set = TrustStoreSet::new(); let verifier = SignatureVerifier::new(&trust_set) .policy(Box::new(BasicPdfSignaturePolicy::new())); ``` -------------------------------- ### Initialize SVT model for issuance Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/index.html Create an SvtModel using the builder pattern after verifying a PDF signature. ```rust // After verifying a PDF signature, build SVT claims: let model = SvtModel::builder() .issuer_id("https://svt.example.com") .build(); // Use SvtIssuer to create a signed JWT // (requires a signing key and certificate chain) ``` -------------------------------- ### Perform a three-phase CMS signing flow Source: https://docs.rs/underskrift/0.1.4/underskrift/cms/builder/struct.PdfCmsBuilder.html Demonstrates the two-phase remote signing process using pre_sign to generate a hash for external signing and complete_cms to finalize the structure. ```rust let builder = PdfCmsBuilder::new(&signer_info).profile(CmsProfile::Pades); let pre = builder.pre_sign(data_hash)?; // Send pre.attrs_hash to remote signing service... let signature_bytes = remote_sign(&pre.attrs_hash); let cms_der = builder.complete_cms(&pre, &signature_bytes)?; ``` -------------------------------- ### Verify PDF Signatures Source: https://docs.rs/underskrift/0.1.4/underskrift/verify/index.html Demonstrates loading a PDF and a trust store to verify all signatures within the document. ```rust use underskrift::verify::{SignatureVerifier, VerificationReport}; use underskrift::trust::{TrustStore, TrustStoreSet}; // Load the PDF and set up trust store let pdf = std::fs::read("signed.pdf")?; let trust = TrustStore::from_pem_file("ca-cert.pem")?; let trust_set = TrustStoreSet::new().with_sig_store(trust); // Verify all signatures let verifier = SignatureVerifier::new(&trust_set); let report = verifier.verify_pdf(&pdf)?; for sig in &report.signatures { println!("{}: {:?}", sig.field_name, sig.status); } ``` -------------------------------- ### TextLine Configuration Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/layout/struct.TextLine.html Methods for configuring the styling of a TextLine instance. ```APIDOC ## Configuration Methods ### pub fn bold(self) -> Self Sets the text line to bold. ### pub fn size(self, size: f32) -> Self Overrides the font size for this line. - **size** (f32) - Required - The font size value. ### pub fn color(self, color: Color) -> Self Overrides the color for this line. - **color** (Color) - Required - The color to apply. ``` -------------------------------- ### ChainBuilder Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/struct.ChainBuilder.html Methods for initializing and configuring the ChainBuilder. ```rust pub fn new() -> ChainBuilder ``` ```rust pub fn http_client(self, client: Client) -> ChainBuilder ``` ```rust pub fn timeout(self, timeout: Duration) -> ChainBuilder ``` -------------------------------- ### Initialize and use TsaClient Source: https://docs.rs/underskrift/0.1.4/underskrift/tsp/client/struct.TsaClient.html Demonstrates creating a new TsaClient instance with custom configuration and requesting a timestamp token for a data hash. ```rust use tsp_ltv::tsp::TsaClient; use tsp_ltv::crypto::algorithm::DigestAlgorithm; let client = TsaClient::new("http://timestamp.digicert.com") .digest_algorithm(DigestAlgorithm::Sha256) .timeout(std::time::Duration::from_secs(10)); let data_hash = DigestAlgorithm::Sha256.digest(b"hello"); let token = client.timestamp(&data_hash).await?; ``` -------------------------------- ### Perform three-phase remote signing Source: https://docs.rs/underskrift/0.1.4/underskrift/remote/index.html Demonstrates the workflow of preparing a PDF for signing, obtaining a hash for an external signer, and finalizing the document with the resulting signature bytes. ```rust use underskrift::remote::{ prepare_signature, finalize_signature, RemoteSignerInfo, RemoteSigningOptions, }; use underskrift::crypto::algorithm::{DigestAlgorithm, SignatureAlgorithm}; let pdf = std::fs::read("document.pdf")?; // Certificate and algorithm info (no private key!) let signer_info = RemoteSignerInfo { certificate_der: std::fs::read("signer_cert.der")?, chain_der: vec![ std::fs::read("signer_cert.der")?, std::fs::read("ca_cert.der")?, ], digest_algorithm: DigestAlgorithm::Sha256, signature_algorithm: SignatureAlgorithm::RsaPkcs1v15, }; // Phase 1: Prepare let prepared = prepare_signature(&pdf, &signer_info, &RemoteSigningOptions::default())?; // Phase 2: Send hash to remote signer (your code) // let signature_bytes = remote_kms.sign(&prepared.attrs_hash)?; // Phase 3: Finalize let signed_pdf = finalize_signature(prepared, &signature_bytes)?; std::fs::write("signed.pdf", signed_pdf)?; ``` -------------------------------- ### PdfSigner::new Source: https://docs.rs/underskrift/0.1.4/underskrift/signer/struct.PdfSigner.html Creates a new instance of PdfSigner with default configuration options. ```APIDOC ### pub fn new() -> Self Creates a new PdfSigner with default options. ``` -------------------------------- ### CrlClient::new Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/struct.CrlClient.html Creates a new CRL client instance with default settings, including a 1-hour grace period. ```APIDOC ## pub fn new() -> CrlClient ### Description Creates a new CRL client with default settings. ### Returns - **CrlClient** - A new instance of the CRL client. ``` -------------------------------- ### Create a new SvtIssuer Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/issuer/struct.SvtIssuer.html Initializes a new issuer with a JWS algorithm, a PKCS#8 DER-encoded private key, and a DER-encoded X.509 certificate chain. ```rust pub fn new( jws_algorithm: &str, private_key_der: Vec, certificate_chain_der: Vec>, ) -> Result ``` -------------------------------- ### prepare_signature Source: https://docs.rs/underskrift/0.1.4/underskrift/remote/index.html Phase 1: Prepares a PDF for remote signing by parsing the document, building the signature dictionary, and computing the hash that must be signed. ```APIDOC ## prepare_signature ### Description Prepares a PDF for remote signing. This function returns a `PreparedSignature` containing the hash to be signed and the state required to finalize the process. ### Signature `pub fn prepare_signature(pdf: &[u8], signer_info: &RemoteSignerInfo, options: &RemoteSigningOptions) -> Result` ### Parameters - **pdf** (&[u8]) - The raw bytes of the PDF document. - **signer_info** (&RemoteSignerInfo) - Certificate and algorithm information for the remote signer. - **options** (&RemoteSigningOptions) - Configuration options for the signing process. ``` -------------------------------- ### SoftwareSigner::from_pkcs12_file Source: https://docs.rs/underskrift/0.1.4/underskrift/crypto/software/struct.SoftwareSigner.html Loads a signer from a PKCS#12 file. ```APIDOC ## pub fn from_pkcs12_file(path: impl AsRef, password: &str) -> Result ### Description Loads a signer from a PKCS#12 (.p12 / .pfx) file using the provided password. ### Parameters - **path** (impl AsRef) - Required - The file path to the PKCS#12 file. - **password** (&str) - Required - The password to decrypt the PKCS#12 file. ``` -------------------------------- ### Define an AlgorithmRegistry allowlist Source: https://docs.rs/underskrift/0.1.4/underskrift/crypto/algorithm/struct.AlgorithmRegistry.html Demonstrates how to restrict allowed algorithms by using builder methods on a new AlgorithmRegistry instance. ```rust use tsp_ltv::crypto::algorithm::{AlgorithmRegistry, DigestAlgorithm, SignatureAlgorithm}; // Allow only SHA-256/384/512 with RSA and ECDSA (no SHA-3, no Ed25519) let registry = AlgorithmRegistry::new() .allow_digest(DigestAlgorithm::Sha256) .allow_digest(DigestAlgorithm::Sha384) .allow_digest(DigestAlgorithm::Sha512) .allow_signature(SignatureAlgorithm::RsaPkcs1v15) .allow_signature(SignatureAlgorithm::RsaPss) .allow_signature(SignatureAlgorithm::EcdsaP256) .allow_signature(SignatureAlgorithm::EcdsaP384); assert!(registry.is_digest_allowed(DigestAlgorithm::Sha256)); assert!(!registry.is_digest_allowed(DigestAlgorithm::Sha3_256)); ``` -------------------------------- ### Sign a PDF document with PdfSigner Source: https://docs.rs/underskrift/0.1.4/underskrift/signer/struct.PdfSigner.html Demonstrates the basic workflow for signing a PDF file using a PKCS#12 certificate. ```rust use underskrift::{PdfSigner, SigningOptions, SoftwareSigner}; let pdf = std::fs::read("document.pdf")?; let signer = SoftwareSigner::from_pkcs12_file("key.p12", "pass")?; let signed = PdfSigner::new() .options(SigningOptions::default()) .sign(&pdf, &signer) .await?; ``` -------------------------------- ### PkixPdfSignaturePolicy Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/policy/pkix/struct.PkixPdfSignaturePolicy.html Methods for configuring and initializing a PKIX PDF signature policy. ```APIDOC ## PkixPdfSignaturePolicy::new() ### Description Creates a new instance of PkixPdfSignaturePolicy with default settings. ## PkixPdfSignaturePolicy::grace_period(period: Duration) ### Description Sets the revocation grace period for the signature policy. ## PkixPdfSignaturePolicy::require_revocation_check(require: bool) ### Description Configures whether the revocation status of the certificate must be verified. ## PkixPdfSignaturePolicy::require_no_modifications(require: bool) ### Description Sets whether the policy requires that no non-safe modifications have been made to the document. ## PkixPdfSignaturePolicy::enforce_current_time_validation(enforce: bool) ### Description Configures whether the policy enforces certificate validity based on the current time. ## PkixPdfSignaturePolicy::use_timestamp_time(use_ts: bool) ### Description Sets whether the policy should use the timestamp time as the reference for validation. ``` -------------------------------- ### IncrementalWriter::new Source: https://docs.rs/underskrift/0.1.4/underskrift/core/incremental/struct.IncrementalWriter.html Creates a new instance of the IncrementalWriter. ```APIDOC ## pub fn new(original: Vec, prev_size: u32, prev_xref_offset: usize, root_id: ObjectId, contents_hex_size: usize) -> Self ### Description Initializes a new incremental writer for a PDF document. ### Parameters - **original** (Vec) - The complete original PDF bytes. - **prev_size** (u32) - The /Size from the original trailer (next object number). - **prev_xref_offset** (usize) - Byte offset of the original xref table (for /Prev). - **root_id** (ObjectId) - The /Root catalog object ID. - **contents_hex_size** (usize) - Number of hex characters to reserve for /Contents. ``` -------------------------------- ### SignatureAlgorithm::all Source: https://docs.rs/underskrift/0.1.4/underskrift/enum.SignatureAlgorithm.html Returns a slice containing all known signature algorithms. ```APIDOC ## pub fn all() -> &'static [SignatureAlgorithm] ### Description Returns a static slice containing all known signature algorithms supported by the library. ``` -------------------------------- ### TsaClient::new Source: https://docs.rs/underskrift/0.1.4/underskrift/tsp/client/struct.TsaClient.html Creates a new TsaClient instance for the specified TSA server URL. ```APIDOC ## pub fn new(url: &str) -> TsaClient ### Description Creates a new TSA client for the given URL with default settings (SHA-256, 30s timeout, certReq=true). ### Parameters - **url** (&str) - Required - The URL of the TSA server. ``` -------------------------------- ### Color Presets Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/layout/struct.Color.html Static methods to retrieve common color instances. ```APIDOC ## Color Presets ### Methods - **Color::black() -> Self**: Returns a black color instance. - **Color::white() -> Self**: Returns a white color instance. - **Color::dark_gray() -> Self**: Returns a dark gray color instance, commonly used for signature text. ``` -------------------------------- ### SignatureTemplate Builder Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/layout/struct.SignatureTemplate.html Methods used to construct and configure a SignatureTemplate instance. ```APIDOC ## SignatureTemplate::new(lines: Vec) -> Self ### Description Creates a new template with the given lines. ## SignatureTemplate::font_size(self, size: f32) -> Self ### Description Sets the font size for the signature text. ## SignatureTemplate::padding(self, padding: f32) -> Self ### Description Sets the padding for the signature. ## SignatureTemplate::color(self, color: Color) -> Self ### Description Sets the text color. ## SignatureTemplate::line_spacing(self, spacing: f32) -> Self ### Description Sets the line spacing multiplier. ## SignatureTemplate::font_name(self, name: impl Into) -> Self ### Description Sets the font name (must be a Standard 14 PDF font name). ## SignatureTemplate::bold_font_name(self, name: impl Into) -> Self ### Description Sets the bold font name (must be a Standard 14 PDF font name). ## SignatureTemplate::first_line_bold(self, bold: bool) -> Self ### Description Sets whether the first line is rendered bold. ``` -------------------------------- ### Color::new Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/layout/struct.Color.html Creates a new color instance from red, green, and blue components. ```APIDOC ## pub fn new(r: f32, g: f32, b: f32) -> Self ### Description Creates a new color from RGB components. Each component should be a value between 0.0 and 1.0. ### Parameters - **r** (f32) - Red component (0.0 to 1.0) - **g** (f32) - Green component (0.0 to 1.0) - **b** (f32) - Blue component (0.0 to 1.0) ``` -------------------------------- ### Define QUALITY_QC_QSCD constant Source: https://docs.rs/underskrift/0.1.4/underskrift/report/types/constant.QUALITY_QC_QSCD.html Represents the URI for signature quality: EU Qualified Certificate on QSCD. ```rust pub const QUALITY_QC_QSCD: &str = "http://id.swedenconnect.se/sigval-report/quality/qc-qscd"; ``` -------------------------------- ### is_supported(jws_algo: &str) -> bool Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/algo/fn.is_supported.html Checks if a given JWS algorithm string is supported. ```APIDOC ## Function: is_supported ### Description Checks if a JWS algorithm is supported. ### Signature `pub fn is_supported(jws_algo: &str) -> bool` ### Parameters - **jws_algo** (&str) - The JWS algorithm identifier to check. ### Returns - **bool** - Returns true if the algorithm is supported, false otherwise. ``` -------------------------------- ### Building Certificate Chains Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/struct.ChainBuilder.html Methods to construct certificate chains from a leaf certificate or a list of available certificates. ```rust pub async fn build_chain( &self, leaf: &CertificateInner, trust_store: &TrustStore, ) -> Result>, LtvError> ``` ```rust pub fn build_chain_from_certs( leaf: &CertificateInner, available_certs: &[CertificateInner], trust_store: &TrustStore, ) -> Vec> ``` -------------------------------- ### TsaClientPool::new Source: https://docs.rs/underskrift/0.1.4/underskrift/tsp/client/struct.TsaClientPool.html Creates a new pool from a list of TsaClient instances. Panics if the provided list is empty. ```APIDOC ## pub fn new(clients: Vec) -> TsaClientPool ### Description Creates a new pool from a list of TSA clients. Panics if the provided list is empty. ### Parameters - **clients** (Vec) - Required - A list of TSA clients to include in the pool. ``` -------------------------------- ### IncrementalWriter Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/core/incremental/struct.IncrementalWriter.html Methods for initializing the writer, adding objects, setting signature dictionary IDs, and finalizing the incremental update. ```rust pub fn new( original: Vec, prev_size: u32, prev_xref_offset: usize, root_id: ObjectId, contents_hex_size: usize, ) -> Self ``` ```rust pub fn add_object(&mut self, id: ObjectId, object: Object) ``` ```rust pub fn set_sig_dict_id(&mut self, id: ObjectId) ``` ```rust pub fn write(self) -> Result<(Vec, ByteRange), CoreError> ``` -------------------------------- ### Define POLICY_PKIX constant Source: https://docs.rs/underskrift/0.1.4/underskrift/report/types/constant.POLICY_PKIX.html Represents the URI for full PKIX path validation with revocation. ```rust pub const POLICY_PKIX: &str = "http://id.swedenconnect.se/svt/sigval-policy/pkix/01"; ``` -------------------------------- ### prepare_image function signature Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/image/fn.prepare_image.html The function signature for preparing image data for PDF embedding. ```rust pub fn prepare_image( data: &[u8], format: ImageFormat, ) -> Result ``` -------------------------------- ### build_appearance Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/fn.build_appearance.html Builds an appearance stream for a given visible signature configuration. This function dispatches to the appropriate builder based on the layout type and uses a default context for custom layouts. ```APIDOC ## Function: build_appearance ### Description Builds an appearance stream for the given visible signature configuration. This is the main entry point that dispatches to the appropriate builder based on the layout type. ### Signature `pub fn build_appearance(config: &VisibleSignatureConfig, page_width: f32, page_height: f32) -> Result` ### Parameters - **config** (&VisibleSignatureConfig) - The configuration object for the visible signature. - **page_width** (f32) - The width of the page. - **page_height** (f32) - The height of the page. ### Returns - **Result** - Returns an `AppearanceStream` on success, or a `VisualError` if the build process fails. ``` -------------------------------- ### TextLine::new Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/layout/struct.TextLine.html Creates a new instance of a TextLine with the specified text content. ```APIDOC ## pub fn new(text: impl Into) -> Self ### Description Creates a new text line with the given content. ### Parameters - **text** (impl Into) - Required - The text content to be displayed. ``` -------------------------------- ### OcspClient Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/ocsp/struct.OcspClient.html Methods for initializing and using the OcspClient to perform OCSP revocation checks. ```APIDOC ## pub fn new() -> OcspClient ### Description Creates a new OCSP client instance with default settings. ## pub fn http_client(self, client: Client) -> OcspClient ### Description Configures the HTTP client used by the OcspClient for network requests. ## pub fn timeout(self, timeout: Duration) -> OcspClient ### Description Sets the request timeout duration for the OCSP client. ## pub fn extract_ocsp_urls(cert: &CertificateInner) -> Vec ### Description Extracts OCSP responder URLs from a certificate’s Authority Information Access (AIA) extension. ## pub async fn fetch_ocsp_response(&self, cert: &CertificateInner, issuer: &CertificateInner) -> Result, LtvError> ### Description Fetches an OCSP response for a certificate. It builds an OCSP request for the provided certificate issued by the specified issuer, sends it to the responder URL, and returns the raw DER-encoded response. ## pub async fn fetch_ocsp_response_with_nonce(&self, cert: &CertificateInner, issuer: &CertificateInner) -> Result<(Vec, Vec), LtvError> ### Description Fetches an OCSP response including a nonce for replay protection. Returns a tuple containing the DER-encoded response and the nonce bytes. ``` -------------------------------- ### SigningOptions Struct Definition Source: https://docs.rs/underskrift/0.1.4/underskrift/signer/struct.SigningOptions.html The definition of the SigningOptions struct showing all available configuration fields for PDF signing. ```rust pub struct SigningOptions {Show 15 fields pub sub_filter: SubFilter, pub pades_level: PadesLevel, pub digest_algorithm: DigestAlgorithm, pub field_name: String, pub page: u32, pub reason: Option, pub location: Option, pub contact_info: Option, pub content_size: usize, pub tsa_url: Option, pub certify: bool, pub algorithm_registry: Option, pub visible_signature: Option, pub cms_signing_time: Option, pub signing_time_placement: SigningTimePlacement, } ``` -------------------------------- ### SoftwareSigner::from_pkcs12_data Source: https://docs.rs/underskrift/0.1.4/underskrift/crypto/software/struct.SoftwareSigner.html Loads a signer from PKCS#12 bytes. ```APIDOC ## pub fn from_pkcs12_data(data: &[u8], password: &str) -> Result ### Description Loads a signer from raw PKCS#12 byte data using the provided password. ### Parameters - **data** (&[u8]) - Required - The raw byte data of the PKCS#12 file. - **password** (&str) - Required - The password to decrypt the data. ``` -------------------------------- ### Create New SvtClaims Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/claims/struct.SvtClaims.html Constructor for initializing SvtClaims with version 1.0 and no extensions. ```rust pub fn new( profile: SVTProfile, hash_algo: String, sig: Vec, ) -> Self ``` -------------------------------- ### TrustStoreSet Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/trust/struct.TrustStoreSet.html Methods for creating, configuring, and accessing trust stores within a TrustStoreSet. ```APIDOC ## pub fn new() -> TrustStoreSet ### Description Creates an empty TrustStoreSet with no stores configured. ## pub fn with_sig_store(self, store: TrustStore) -> TrustStoreSet ### Description Sets the signature validation trust store and returns the updated TrustStoreSet. ## pub fn with_tsa_store(self, store: TrustStore) -> TrustStoreSet ### Description Sets the timestamp authority trust store and returns the updated TrustStoreSet. ## pub fn with_svt_store(self, store: TrustStore) -> TrustStoreSet ### Description Sets the SVT issuer trust store and returns the updated TrustStoreSet. ## pub fn get(&self, kind: StoreKind) -> Option<&TrustStore> ### Description Retrieves the trust store associated with the specified StoreKind. ## pub fn get_mut(&mut self, kind: StoreKind) -> Option<&mut TrustStore> ### Description Retrieves a mutable reference to the trust store associated with the specified StoreKind. ## pub fn sig(&self) -> Option<&TrustStore> ### Description Returns the signature trust store if configured. ## pub fn tsa(&self) -> Option<&TrustStore> ### Description Returns the timestamp authority trust store if configured. ## pub fn svt(&self) -> Option<&TrustStore> ### Description Returns the SVT trust store if configured. ## pub fn has_any(&self) -> bool ### Description Checks if at least one trust store is configured in the set. ## pub fn set(&mut self, kind: StoreKind, store: TrustStore) ### Description Sets a specific trust store by its kind. ``` -------------------------------- ### prepare_signature Source: https://docs.rs/underskrift/0.1.4/underskrift/remote/fn.prepare_signature.html Prepares a PDF for remote signing by generating the necessary hash and state without requiring a private key. ```APIDOC ## prepare_signature ### Description Phase 1: Prepare a PDF for remote signing. Parses the PDF, builds signature structures, computes the ByteRange hash, constructs CMS signed attributes, and returns the hash that must be signed along with all state needed to finalize. This function does NOT require a private key. ### Signature `pub fn prepare_signature(pdf_data: &[u8], signer_info: &RemoteSignerInfo, options: &RemoteSigningOptions) -> Result` ### Parameters - **pdf_data** (&[u8]) - The raw PDF data to be signed. - **signer_info** (&RemoteSignerInfo) - Contains the signer's certificate, chain, and algorithm information. - **options** (&RemoteSigningOptions) - Configuration options for the remote signing process. ### Returns - **Result** - Returns a `PreparedSignature` containing the hash to be signed and state for finalization, or a `PdfSignError` if the operation fails. ### Errors - The PDF cannot be parsed. - The algorithms are rejected by the optional `AlgorithmRegistry`. - The certificate cannot be DER-decoded. ``` -------------------------------- ### build_image_and_text_appearance Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/fn.build_image_and_text_appearance.html Builds an appearance stream for a combined image and text layout based on the provided configurations and dimensions. ```APIDOC ## Function: build_image_and_text_appearance ### Description Builds an appearance stream for a combined image and text layout. The image and text are arranged according to the `Arrangement` setting, splitting the available space between them. ### Signature `pub fn build_image_and_text_appearance(image_config: &ImageConfig, text_config: &TextConfig, arrangement: Arrangement, width: f32, height: f32, background: Option<&Color>, border: Option<&Border>) -> Result` ### Parameters - **image_config** (&ImageConfig) - Configuration for the image component. - **text_config** (&TextConfig) - Configuration for the text component. - **arrangement** (Arrangement) - The layout strategy for positioning image and text. - **width** (f32) - The total width of the appearance. - **height** (f32) - The total height of the appearance. - **background** (Option<&Color>) - Optional background color. - **border** (Option<&Border>) - Optional border configuration. ### Returns - **Result** - Returns an `AppearanceStream` on success, or a `VisualError` if the construction fails. ``` -------------------------------- ### build_default_text_appearance Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/index.html Creates a default text-based signature appearance. ```APIDOC ## build_default_text_appearance ### Description Create a default text-based signature appearance from signing metadata. ### Signature `pub fn build_default_text_appearance(metadata: SigningMetadata) -> Result` ``` -------------------------------- ### EtsiReportGenerator::with_defaults Source: https://docs.rs/underskrift/0.1.4/underskrift/report/generator/struct.EtsiReportGenerator.html Creates a new instance of the EtsiReportGenerator using default configuration settings. ```APIDOC ## pub fn with_defaults() -> Self ### Description Create a generator with default options. ``` -------------------------------- ### EtsiReportGenerator::new Source: https://docs.rs/underskrift/0.1.4/underskrift/report/generator/struct.EtsiReportGenerator.html Creates a new instance of the EtsiReportGenerator with the specified configuration options. ```APIDOC ## pub fn new(options: ReportOptions) -> Self ### Description Creates a new generator with the given options. ### Parameters - **options** (ReportOptions) - Required - Configuration options for the report generator. ``` -------------------------------- ### Create a default text appearance in Rust Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/index.html Generates a default text-based signature appearance using standard PDF fonts. Requires the visual module imports. ```rust use underskrift::visual::layout::*; use underskrift::visual::appearance::build_default_text_appearance; // Create a default text appearance let appearance = build_default_text_appearance( "John Doe", Some("Approval"), Some("Stockholm"), None, 200.0, 60.0, ).unwrap(); // The appearance.content contains the PDF content stream // The appearance.font_resources lists fonts needed assert!(!appearance.content.is_empty()); ``` -------------------------------- ### SigningOptions Source: https://docs.rs/underskrift/0.1.4/underskrift/signer/index.html Configuration options used to define the parameters for the PDF signing process. ```APIDOC ## Struct: SigningOptions ### Description Configuration options for PDF signing, passed to the PdfSigner to customize the output and signing behavior. ``` -------------------------------- ### Accessing the QUALITY_QC constant Source: https://docs.rs/underskrift/0.1.4/underskrift/report/types/constant.QUALITY_QC.html Defines the URI string for the EU Qualified Certificate signature quality. ```rust pub const QUALITY_QC: &str = "http://id.swedenconnect.se/sigval-report/quality/qc"; ``` -------------------------------- ### Initialize TsaClientPool Source: https://docs.rs/underskrift/0.1.4/underskrift/tsp/client/struct.TsaClientPool.html Create a new pool by providing a vector of TsaClient instances. ```rust use tsp_ltv::tsp::{TsaClient, TsaClientPool}; let pool = TsaClientPool::new(vec![ TsaClient::new("http://timestamp.digicert.com"), TsaClient::new("http://timestamp.globalsign.com/tsa/r6advanced1"), ]); ``` -------------------------------- ### create_svt_sealed_pdf Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/embed/fn.create_svt_sealed_pdf.html Creates an SVT-sealed PDF by embedding an SVT JWT as a DocTimeStamp. ```APIDOC ## Function: create_svt_sealed_pdf ### Description Create an SVT-sealed PDF by embedding an SVT JWT as a DocTimeStamp. This function prepares the PDF with a placeholder, computes the hash, builds a TSTInfo carrying the SVT JWT, wraps it in a CMS SignedData timestamp token, and injects the token into the PDF. ### Signature `pub fn create_svt_sealed_pdf(pdf_data: &[u8], svt_jwt: &str, signer: &dyn CryptoSigner, options: Option<&SvtSealOptions>) -> Result, SvtError>` ### Arguments - **pdf_data** (&[u8]) - The PDF to seal (may already be signed). - **svt_jwt** (&str) - The signed SVT JWT string (from SvtIssuer::issue()). - **signer** (&dyn CryptoSigner) - The signing key for the self-signed CMS timestamp token. - **options** (Option<&SvtSealOptions>) - Optional embedding configuration. ### Returns - **Result, SvtError>** - The PDF with the SVT document timestamp appended as an incremental update. ``` -------------------------------- ### TryFrom and TryInto Implementations Source: https://docs.rs/underskrift/0.1.4/underskrift/policy/struct.PolicyResult.html Provides fallible conversion traits. ```rust impl TryFrom for T where U: Into, type Error = Infallible fn try_from(value: U) -> Result>::Error> ``` ```rust impl TryInto for T where U: TryFrom, type Error = >::Error fn try_into(self) -> Result>::Error> ``` -------------------------------- ### SvtSealOptions Struct Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/embed/struct.SvtSealOptions.html Configuration options for creating an SVT-sealed PDF. ```APIDOC ## Struct SvtSealOptions ### Description Options for creating an SVT-sealed PDF. ### Fields - **content_size** (Option) - Size to reserve for the CMS token in /Contents (bytes, not hex chars). Must be large enough for SVT JWT, cert chain, and CMS overhead. Default: computed from JWT + chain size + 2000 bytes overhead. - **field_name** (String) - Signature field name for the timestamp. Default: “SVTDocTimeStamp” - **page** (u32) - Page to attach the annotation to (0-indexed). Default: 0 (first page) ``` -------------------------------- ### Function Signature for build_appearance_with_context Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/fn.build_appearance_with_context.html The function signature defines the required configuration, page dimensions, and optional context for building an appearance stream. ```rust pub fn build_appearance_with_context( config: &VisibleSignatureConfig, page_width: f32, page_height: f32, ctx: Option<&AppearanceContext>, ) -> Result ``` -------------------------------- ### AlgorithmRegistry Methods Source: https://docs.rs/underskrift/0.1.4/underskrift/crypto/algorithm/struct.AlgorithmRegistry.html Methods for creating, configuring, and validating algorithm registries. ```APIDOC ## AlgorithmRegistry Methods ### new() Creates a new, empty registry with no algorithms allowed. ### allow_all() Creates a registry that allows all supported algorithms. ### standard() Creates a registry pre-configured for production PDF signing, including common SHA-2 and RSA/ECDSA algorithms. ### allow_digest(alg: DigestAlgorithm) Adds a specific digest algorithm to the allowed set. ### allow_signature(alg: SignatureAlgorithm) Adds a specific signature algorithm to the allowed set. ### is_digest_allowed(alg: DigestAlgorithm) -> bool Checks if a specific digest algorithm is permitted. ### is_signature_allowed(alg: SignatureAlgorithm) -> bool Checks if a specific signature algorithm is permitted. ### validate(sig_alg: SignatureAlgorithm, digest_alg: DigestAlgorithm) -> Result<(), String> Validates that both the signature and digest algorithms are allowed. Returns Ok(()) if valid, or an error string if rejected. ### allowed_digests() -> &[DigestAlgorithm] Returns the list of currently allowed digest algorithms. ### allowed_signatures() -> &[SignatureAlgorithm] Returns the list of currently allowed signature algorithms. ``` -------------------------------- ### check_key_usage Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/fn.check_key_usage.html Parses the Key Usage extension from a certificate. ```APIDOC ## Function: check_key_usage ### Description Parses the Key Usage extension from a certificate. Returns `Some(KeyUsageBits)` if the extension is present, `None` otherwise. ### Signature `pub fn check_key_usage(cert: &CertificateInner) -> Result, LtvError>` ### Parameters - **cert** (&CertificateInner) - The certificate to parse for the Key Usage extension. ### Returns - **Result, LtvError>** - Returns the KeyUsageBits if found, None if not present, or an LtvError if parsing fails. ``` -------------------------------- ### build_image_appearance Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/index.html Builds an appearance stream for an image-only layout. ```APIDOC ## build_image_appearance ### Description Build an appearance stream for an image-only layout. ### Signature `pub fn build_image_appearance(image: ImageResource) -> Result` ``` -------------------------------- ### TsaClientPool::from_url Source: https://docs.rs/underskrift/0.1.4/underskrift/tsp/client/struct.TsaClientPool.html Creates a pool from a single URL with default settings. ```APIDOC ## pub fn from_url(url: &str) -> TsaClientPool ### Description Creates a pool from a single URL with default settings. ### Parameters - **url** (&str) - Required - The URL of the TSA service. ``` -------------------------------- ### ChainBuilder::build_chain Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/chain/struct.ChainBuilder.html Builds a certificate chain by fetching intermediate certificates via AIA. ```APIDOC ### Method `pub async fn build_chain(&self, leaf: &CertificateInner, trust_store: &TrustStore) -> Result>, LtvError>` ### Description Builds a certificate chain starting from the leaf certificate up to a trust anchor by following AIA caIssuers URLs. ### Warning This method performs name-based ordering only and does not perform signature verification. The result must be verified using `crate::trust::TrustStore::verify_chain` before use. This method performs outbound network requests based on untrusted input. ``` -------------------------------- ### generate_nonce function signature Source: https://docs.rs/underskrift/0.1.4/underskrift/tsp/fn.generate_nonce.html Displays the function signature for generating a 64-bit nonce. ```rust pub fn generate_nonce() -> u64 ``` -------------------------------- ### check_basic_constraints Source: https://docs.rs/underskrift/0.1.4/underskrift/ltv/fn.check_basic_constraints.html Parses the Basic Constraints extension from a certificate. Returns a tuple containing a boolean indicating if the certificate is a CA and an optional integer for the path length constraint. ```APIDOC ## check_basic_constraints ### Signature `pub fn check_basic_constraints(cert: &CertificateInner) -> Result<(bool, Option), LtvError>` ### Description Parses the Basic Constraints extension from a certificate. If the certificate has no Basic Constraints extension, it returns `(false, None)`. ### Parameters - **cert** (&CertificateInner) - The certificate to parse. ### Returns - **Result<(bool, Option), LtvError>** - A tuple where the first element is a boolean (`is_ca`) indicating if the `cA` field is TRUE, and the second is an optional integer (`path_len_constraint`) representing the `pathLenConstraint`. ``` -------------------------------- ### PdfSigner::options Source: https://docs.rs/underskrift/0.1.4/underskrift/signer/struct.PdfSigner.html Configures the signing options for the PdfSigner instance. ```APIDOC ### pub fn options(self, options: SigningOptions) -> Self Sets the signing options to be used during the PDF signing process. ``` -------------------------------- ### build_sig_dict Source: https://docs.rs/underskrift/0.1.4/underskrift/core/sig_dict/index.html Builds a signature dictionary with placeholder ByteRange and Contents entries. ```APIDOC ## build_sig_dict ### Description Builds a signature dictionary with placeholder ByteRange and Contents entries for PDF signing. ### Signature `pub fn build_sig_dict(...)` ### Parameters - The function constructs dictionaries with proper `/Filter`, `/SubFilter`, `/ByteRange`, and `/Contents` entries. ``` -------------------------------- ### From and Into Conversions Source: https://docs.rs/underskrift/0.1.4/underskrift/policy/struct.PolicyResult.html Standard trait implementations for type conversions. ```rust impl From for T fn from(t: T) -> T ``` ```rust impl Into for T where U: From, fn into(self) -> U ``` -------------------------------- ### build_image_appearance Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/fn.build_image_appearance.html Builds an appearance stream for an image-only layout, scaling the image to fit within the provided width and height. ```APIDOC ## Function: build_image_appearance ### Description Builds an appearance stream for an image-only layout. The image is scaled to fit within the given dimensions according to the `ImageScale` setting. The content stream uses `cm` to transform coordinates and `Do` to paint the image XObject. ### Signature `pub fn build_image_appearance(image_config: &ImageConfig, width: f32, height: f32, background: Option<&Color>, border: Option<&Border>) -> Result` ### Parameters - **image_config** (&ImageConfig) - Configuration for the image. - **width** (f32) - The target width for the image. - **height** (f32) - The target height for the image. - **background** (Option<&Color>) - Optional background color. - **border** (Option<&Border>) - Optional border configuration. ### Returns - **Result** - Returns an `AppearanceStream` on success, or a `VisualError` if the operation fails. ``` -------------------------------- ### build_tst_info_with_svt Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/embed/fn.build_tst_info_with_svt.html Builds a DER-encoded TSTInfo that carries an SVT JWT as an extension. ```APIDOC ## Function: build_tst_info_with_svt ### Description Builds a DER-encoded TSTInfo structure that carries an SVT JWT as an extension. The resulting structure follows the TSTInfo sequence definition including version, policy, messageImprint, serialNumber, genTime, and extensions. ### Signature `pub fn build_tst_info_with_svt(svt_jwt: &str, message_hash: &[u8], digest_alg: DigestAlgorithm) -> Result, SvtError>` ### Arguments - **svt_jwt** (&str) - The signed SVT JWT string to embed. - **message_hash** (&[u8]) - The hash of the PDF ByteRange-selected bytes. - **digest_alg** (DigestAlgorithm) - The digest algorithm used for the hash. ### Returns - **Result, SvtError>** - The DER-encoded TSTInfo bytes on success, or an SvtError on failure. ``` -------------------------------- ### build_svt_timestamp_token Source: https://docs.rs/underskrift/0.1.4/underskrift/svt/embed/fn.build_svt_timestamp_token.html Builds a CMS ContentInfo wrapping a SignedData that contains the TSTInfo, creating a self-signed timestamp token. ```APIDOC ## build_svt_timestamp_token ### Description Builds a CMS ContentInfo wrapping a SignedData that contains the TSTInfo. This creates a self-signed timestamp token (not from an external TSA). ### Signature `pub fn build_svt_timestamp_token(tst_info_der: &[u8], signer: &dyn CryptoSigner) -> Result, SvtError>` ### Arguments - **tst_info_der** (&[u8]) - DER-encoded TSTInfo (from build_tst_info_with_svt). - **signer** (&dyn CryptoSigner) - The signing key for the timestamp token. ### Returns - **Result, SvtError>** - DER-encoded CMS ContentInfo bytes on success, or an SvtError on failure. ``` -------------------------------- ### build_appearance_with_context Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/fn.build_appearance_with_context.html Builds an appearance stream with an optional AppearanceContext for custom renderers. If the context is None and the layout is Custom, a default context is generated based on the provided dimensions. ```APIDOC ## Function: build_appearance_with_context ### Signature `pub fn build_appearance_with_context(config: &VisibleSignatureConfig, page_width: f32, page_height: f32, ctx: Option<&AppearanceContext>) -> Result` ### Description Builds an appearance stream with an optional `AppearanceContext` for custom renderers. When `ctx` is `None` and the layout is `Custom`, a default context with just the dimensions is created. For non-`Custom` layouts, `ctx` is ignored. ### Parameters - **config** (&VisibleSignatureConfig) - The configuration for the visible signature. - **page_width** (f32) - The width of the page. - **page_height** (f32) - The height of the page. - **ctx** (Option<&AppearanceContext>) - An optional context for custom rendering. ### Returns - **Result** - Returns an `AppearanceStream` on success, or a `VisualError` if the operation fails. ``` -------------------------------- ### Function Signature for build_image_appearance Source: https://docs.rs/underskrift/0.1.4/underskrift/visual/appearance/fn.build_image_appearance.html The function signature defines the required parameters for image configuration, dimensions, background, and border settings. ```rust pub fn build_image_appearance( image_config: &ImageConfig, width: f32, height: f32, background: Option<&Color>, border: Option<&Border>, ) -> Result ```