mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-21 07:03:56 +02:00
Merge branch 'main' into teepot_vault
This commit is contained in:
commit
f03a8ba643
7 changed files with 260 additions and 43 deletions
|
@ -147,8 +147,8 @@ impl Default for TelemetryOtlpConfig {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
enable: true,
|
||||
endpoint: "http://127.0.0.1:4317".to_string(),
|
||||
protocol: "grpc".to_string(),
|
||||
endpoint: "http://127.0.0.1:4318/v1/logs".to_string(),
|
||||
protocol: "http/json".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,15 +269,31 @@ fn init_telemetry(
|
|||
)
|
||||
.build();
|
||||
|
||||
// Configure the OTLP exporter
|
||||
let logging_provider = SdkLoggerProvider::builder()
|
||||
.with_batch_exporter(
|
||||
opentelemetry_otlp::LogExporter::builder()
|
||||
.with_tonic()
|
||||
// Parse the protocol from the configuration
|
||||
let protocol = protocol_from_string(&config.otlp.protocol)?;
|
||||
|
||||
// Configure the OTLP exporter based on the protocol
|
||||
let exporter_builder = opentelemetry_otlp::LogExporter::builder();
|
||||
|
||||
// Choose transport based on protocol
|
||||
let exporter = match protocol {
|
||||
opentelemetry_otlp::Protocol::Grpc => exporter_builder
|
||||
.with_tonic()
|
||||
.with_endpoint(&config.otlp.endpoint)
|
||||
.with_protocol(protocol)
|
||||
.build()?,
|
||||
opentelemetry_otlp::Protocol::HttpBinary | opentelemetry_otlp::Protocol::HttpJson => {
|
||||
exporter_builder
|
||||
.with_http()
|
||||
.with_endpoint(&config.otlp.endpoint)
|
||||
.with_protocol(protocol_from_string(&config.otlp.protocol)?)
|
||||
.build()?,
|
||||
)
|
||||
.with_protocol(protocol)
|
||||
.build()?
|
||||
}
|
||||
};
|
||||
|
||||
// Configure the logging provider with the exporter
|
||||
let logging_provider = SdkLoggerProvider::builder()
|
||||
.with_batch_exporter(exporter)
|
||||
.with_resource(resource)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -14,15 +14,4 @@ pub mod prover;
|
|||
pub mod quote;
|
||||
pub mod sgx;
|
||||
pub mod tdx;
|
||||
|
||||
/// pad a byte slice to a fixed sized array
|
||||
pub fn pad<const T: usize>(input: &[u8]) -> [u8; T] {
|
||||
let mut output = [0; T];
|
||||
let len = input.len();
|
||||
if len > T {
|
||||
output.copy_from_slice(&input[..T]);
|
||||
} else {
|
||||
output[..len].copy_from_slice(input);
|
||||
}
|
||||
output
|
||||
}
|
||||
pub mod util;
|
||||
|
|
83
crates/teepot/src/util/mod.rs
Normal file
83
crates/teepot/src/util/mod.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright (c) 2023-2025 Matter Labs
|
||||
|
||||
//! utility functions.
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
/// Errors that can occur when padding byte vectors to fixed-size arrays.
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PadError {
|
||||
/// Indicates that the input vector's length exceeds the target array size.
|
||||
///
|
||||
/// # Fields
|
||||
/// * `expected` - The target size of the array in bytes
|
||||
/// * `actual` - The actual length of the input vector in bytes
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use teepot::util::{pad, PadError};
|
||||
/// let long_input = vec![1, 2, 3, 4];
|
||||
/// let result = pad::<2>(&long_input);
|
||||
/// assert!(matches!(
|
||||
/// result,
|
||||
/// Err(PadError::InputTooLong { expected: 2, actual: 4 })
|
||||
/// ));
|
||||
/// ```
|
||||
#[error("Input vector is too long - expected {expected} bytes, got {actual}")]
|
||||
InputTooLong {
|
||||
/// The expected length (target array size)
|
||||
expected: usize,
|
||||
/// The actual length of the provided input
|
||||
actual: usize,
|
||||
},
|
||||
}
|
||||
|
||||
/// Pad a byte vector to a fixed-size array by appending zeros. If the input is longer
|
||||
/// than the target size, returns an error.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `input` - Input byte vector to be padded with zeros
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<[u8; T], PadError>` - A fixed-size array of length T, or a PadError if input is too long
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns `PadError::InputTooLong` if the input vector length exceeds the target array size T,
|
||||
/// containing both the expected and actual sizes
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// # use teepot::util::{pad, PadError};
|
||||
/// let input = vec![1, 2, 3];
|
||||
/// let padded: [u8; 5] = pad(&input)?;
|
||||
/// assert_eq!(padded, [1, 2, 3, 0, 0]);
|
||||
///
|
||||
/// // Error case: input too long
|
||||
/// let long_input = vec![1, 2, 3, 4, 5, 6];
|
||||
/// assert!(matches!(
|
||||
/// pad::<5>(&long_input),
|
||||
/// Err(PadError::InputTooLong { expected: 5, actual: 6 })
|
||||
/// ));
|
||||
/// # Ok::<(), PadError>(())
|
||||
/// ```
|
||||
///
|
||||
/// # Type Parameters
|
||||
/// * `T` - The fixed size of the output array in bytes
|
||||
pub fn pad<const T: usize>(input: &[u8]) -> Result<[u8; T], PadError> {
|
||||
let mut output = [0u8; T];
|
||||
match input.len().cmp(&T) {
|
||||
std::cmp::Ordering::Greater => Err(PadError::InputTooLong {
|
||||
expected: T,
|
||||
actual: input.len(),
|
||||
}),
|
||||
std::cmp::Ordering::Equal => {
|
||||
output.copy_from_slice(input);
|
||||
Ok(output)
|
||||
}
|
||||
std::cmp::Ordering::Less => {
|
||||
output[..input.len()].copy_from_slice(input);
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue