Skip to content

Commit

Permalink
Renamed DynHash to AnyHash (#126)
Browse files Browse the repository at this point in the history
Avoids the possible confusion associating with the `dyn` Rust keyword.
  • Loading branch information
calvinrp committed May 31, 2023
1 parent 1026002 commit 6565977
Show file tree
Hide file tree
Showing 31 changed files with 176 additions and 176 deletions.
10 changes: 5 additions & 5 deletions crates/api/src/v1/fetch.rs
Expand Up @@ -4,7 +4,7 @@ use crate::Status;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::{borrow::Cow, collections::HashMap};
use thiserror::Error;
use warg_crypto::hash::DynHash;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
registry::{LogId, RecordId},
ProtoEnvelopeBody,
Expand All @@ -15,7 +15,7 @@ use warg_protocol::{
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct FetchLogsRequest<'a> {
/// The root checkpoint hash of the registry.
pub root: Cow<'a, DynHash>,
pub root: Cow<'a, AnyHash>,
/// The limit for the number of operator and package records to fetch.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u16>,
Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct FetchLogsResponse {
pub enum FetchError {
/// The provided checkpoint was not found.
#[error("checkpoint `{0}` was not found")]
CheckpointNotFound(DynHash),
CheckpointNotFound(AnyHash),
/// The provided log was not found.
#[error("log `{0}` was not found")]
LogNotFound(LogId),
Expand Down Expand Up @@ -148,14 +148,14 @@ impl<'de> Deserialize<'de> for FetchError {
})?))
}
EntityType::Log => Ok(Self::LogNotFound(
id.parse::<DynHash>()
id.parse::<AnyHash>()
.map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid log id")
})?
.into(),
)),
EntityType::Record => Ok(Self::RecordNotFound(
id.parse::<DynHash>()
id.parse::<AnyHash>()
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
Expand Down
14 changes: 7 additions & 7 deletions crates/api/src/v1/package.rs
Expand Up @@ -4,7 +4,7 @@ use crate::Status;
use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use std::{borrow::Cow, collections::HashMap};
use thiserror::Error;
use warg_crypto::hash::DynHash;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
registry::{LogId, MapCheckpoint, RecordId},
ProtoEnvelopeBody, SerdeEnvelope,
Expand Down Expand Up @@ -32,7 +32,7 @@ pub struct PublishRecordRequest<'a> {
/// The complete set of content sources for the record.
///
/// A registry may not support specifying content sources directly.
pub content_sources: HashMap<DynHash, Vec<ContentSource>>,
pub content_sources: HashMap<AnyHash, Vec<ContentSource>>,
}

/// Represents a package record API entity in a registry.
Expand All @@ -56,7 +56,7 @@ impl PackageRecord {
}

/// Gets the missing content digests of the record.
pub fn missing_content(&self) -> &[DynHash] {
pub fn missing_content(&self) -> &[AnyHash] {
match &self.state {
PackageRecordState::Sourcing {
missing_content, ..
Expand All @@ -78,7 +78,7 @@ pub enum PackageRecordState {
/// The package record needs content sources.
Sourcing {
/// The digests of the missing content.
missing_content: Vec<DynHash>,
missing_content: Vec<AnyHash>,
},
/// The package record is processing.
Processing,
Expand All @@ -94,7 +94,7 @@ pub enum PackageRecordState {
/// The envelope of the package record.
record: ProtoEnvelopeBody,
/// The content sources of the record.
content_sources: HashMap<DynHash, Vec<ContentSource>>,
content_sources: HashMap<AnyHash, Vec<ContentSource>>,
},
}

Expand Down Expand Up @@ -244,14 +244,14 @@ impl<'de> Deserialize<'de> for PackageError {
}),
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::Log => Ok(Self::LogNotFound(
id.parse::<DynHash>()
id.parse::<AnyHash>()
.map_err(|_| {
serde::de::Error::invalid_value(Unexpected::Str(&id), &"a valid log id")
})?
.into(),
)),
EntityType::Record => Ok(Self::RecordNotFound(
id.parse::<DynHash>()
id.parse::<AnyHash>()
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/v1/paths.rs
@@ -1,6 +1,6 @@
//! The paths of the Warg REST API.

use warg_crypto::hash::DynHash;
use warg_crypto::hash::AnyHash;
use warg_protocol::registry::{LogId, RecordId};

/// The path of the "fetch logs" API.
Expand All @@ -24,7 +24,7 @@ pub fn package_record(log_id: &LogId, record_id: &RecordId) -> String {
}

/// The path for a package record's content.
pub fn package_record_content(log_id: &LogId, record_id: &RecordId, digest: &DynHash) -> String {
pub fn package_record_content(log_id: &LogId, record_id: &RecordId, digest: &AnyHash) -> String {
format!("v1/package/{log_id}/record/{record_id}/content/{digest}")
}

Expand Down
22 changes: 11 additions & 11 deletions crates/api/src/v1/proof.rs
Expand Up @@ -5,17 +5,17 @@ use serde::{de::Unexpected, Deserialize, Serialize, Serializer};
use serde_with::{base64::Base64, serde_as};
use std::borrow::Cow;
use thiserror::Error;
use warg_crypto::hash::DynHash;
use warg_crypto::hash::AnyHash;
use warg_protocol::registry::{LogId, LogLeaf, MapCheckpoint};

/// Represents a consistency proof request.
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConsistencyRequest<'a> {
/// The starting log root hash to check for consistency.
pub from: Cow<'a, DynHash>,
pub from: Cow<'a, AnyHash>,
/// The ending log root hash to check for consistency.
pub to: Cow<'a, DynHash>,
pub to: Cow<'a, AnyHash>,
}

/// Represents a consistency proof response.
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct InclusionResponse {
pub enum ProofError {
/// The provided log root was not found.
#[error("log root `{0}` was not found")]
RootNotFound(DynHash),
RootNotFound(AnyHash),
/// The provided log leaf was not found.
#[error("log leaf `{}:{}` was not found", .0.log_id, .0.record_id)]
LeafNotFound(LogLeaf),
Expand All @@ -68,9 +68,9 @@ pub enum ProofError {
#[error("failed to prove inclusion: found root `{found}` but was given root `{root}`")]
IncorrectProof {
/// The provided root.
root: DynHash,
root: AnyHash,
/// The found root.
found: DynHash,
found: AnyHash,
},
/// A failure was encountered while bundling proofs.
#[error("failed to bundle proofs: {0}")]
Expand Down Expand Up @@ -112,8 +112,8 @@ enum BundleError<'a> {
log_id: Cow<'a, LogId>,
},
IncorrectProof {
root: Cow<'a, DynHash>,
found: Cow<'a, DynHash>,
root: Cow<'a, AnyHash>,
found: Cow<'a, AnyHash>,
},
Failure {
message: Cow<'a, str>,
Expand Down Expand Up @@ -198,7 +198,7 @@ impl<'de> Deserialize<'de> for ProofError {
match RawError::<String>::deserialize(deserializer)? {
RawError::NotFound { status: _, ty, id } => match ty {
EntityType::LogRoot => {
Ok(Self::RootNotFound(id.parse::<DynHash>().map_err(|_| {
Ok(Self::RootNotFound(id.parse::<AnyHash>().map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(&id),
&"a valid checkpoint id",
Expand All @@ -210,7 +210,7 @@ impl<'de> Deserialize<'de> for ProofError {
.map(|(log_id, record_id)| {
Ok(LogLeaf {
log_id: log_id
.parse::<DynHash>()
.parse::<AnyHash>()
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(log_id),
Expand All @@ -219,7 +219,7 @@ impl<'de> Deserialize<'de> for ProofError {
})?
.into(),
record_id: record_id
.parse::<DynHash>()
.parse::<AnyHash>()
.map_err(|_| {
serde::de::Error::invalid_value(
Unexpected::Str(record_id),
Expand Down
16 changes: 8 additions & 8 deletions crates/client/src/api.rs
Expand Up @@ -17,7 +17,7 @@ use warg_api::v1::{
ConsistencyRequest, ConsistencyResponse, InclusionRequest, InclusionResponse, ProofError,
},
};
use warg_crypto::hash::{DynHash, HashError, Sha256};
use warg_crypto::hash::{AnyHash, HashError, Sha256};
use warg_protocol::{
registry::{LogId, LogLeaf, MapCheckpoint, MapLeaf, RecordId},
SerdeEnvelope,
Expand Down Expand Up @@ -56,9 +56,9 @@ pub enum ClientError {
)]
IncorrectConsistencyProof {
/// The provided root.
root: DynHash,
root: AnyHash,
/// The found root.
found: DynHash,
found: AnyHash,
},
/// A hash returned from the server was incorrect.
#[error("the server returned an invalid hash: {0}")]
Expand All @@ -74,10 +74,10 @@ pub enum ClientError {
RecordNotPublished(RecordId),
/// Could not find a source for the given content digest.
#[error("no download location could be found for content digest `{0}`")]
NoSourceForContent(DynHash),
NoSourceForContent(AnyHash),
/// All sources for the given content digest returned an error response.
#[error("all sources for content digest `{0}` returned an error response")]
AllSourcesFailed(DynHash),
AllSourcesFailed(AnyHash),
/// An other error occurred during the requested operation.
#[error(transparent)]
Other(#[from] anyhow::Error),
Expand Down Expand Up @@ -243,7 +243,7 @@ impl Client {
&self,
log_id: &LogId,
record_id: &RecordId,
digest: &DynHash,
digest: &AnyHash,
) -> Result<impl Stream<Item = Result<Bytes>>, ClientError> {
tracing::debug!("fetching record `{record_id}` for package `{log_id}`");

Expand Down Expand Up @@ -327,7 +327,7 @@ impl Client {
.first()
.unwrap()
.evaluate(&log_data)
.map(|(from, to)| (DynHash::from(from), DynHash::from(to)))?;
.map(|(from, to)| (AnyHash::from(from), AnyHash::from(to)))?;

if request.from.as_ref() != &from {
return Err(ClientError::IncorrectConsistencyProof {
Expand All @@ -351,7 +351,7 @@ impl Client {
&self,
log_id: &LogId,
record_id: &RecordId,
digest: &DynHash,
digest: &AnyHash,
content: impl Into<Body>,
) -> Result<String, ClientError> {
let url = self
Expand Down
10 changes: 5 additions & 5 deletions crates/client/src/lib.rs
Expand Up @@ -17,7 +17,7 @@ use warg_api::v1::{
proof::{ConsistencyRequest, InclusionRequest},
};
use warg_crypto::{
hash::{DynHash, Hash, Sha256},
hash::{AnyHash, Hash, Sha256},
signing,
};
use warg_protocol::{
Expand Down Expand Up @@ -355,7 +355,7 @@ impl<R: RegistryStorage, C: ContentStorage> Client<R, C> {
checkpoint: &SerdeEnvelope<MapCheckpoint>,
packages: impl IntoIterator<Item = &mut PackageInfo>,
) -> Result<(), ClientError> {
let root: DynHash = Hash::<Sha256>::of(checkpoint.as_ref()).into();
let root: AnyHash = Hash::<Sha256>::of(checkpoint.as_ref()).into();
tracing::info!("updating to checkpoint `{root}`");

let mut operator = self.registry.load_operator().await?.unwrap_or_default();
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<R: RegistryStorage, C: ContentStorage> Client<R, C> {
&self,
log_id: &LogId,
record_id: &RecordId,
digest: &DynHash,
digest: &AnyHash,
) -> Result<PathBuf, ClientError> {
match self.content.content_location(digest) {
Some(path) => {
Expand Down Expand Up @@ -632,7 +632,7 @@ pub struct PackageDownload {
/// The package version that was downloaded.
pub version: Version,
/// The digest of the package contents.
pub digest: DynHash,
pub digest: AnyHash,
/// The path to the downloaded package contents.
pub path: PathBuf,
}
Expand Down Expand Up @@ -705,7 +705,7 @@ pub enum ClientError {
#[error("content with digest `{digest}` was not found in client storage")]
ContentNotFound {
/// The digest of the missing content.
digest: DynHash,
digest: AnyHash,
},

/// The package log is empty and cannot be validated.
Expand Down
12 changes: 6 additions & 6 deletions crates/client/src/storage.rs
Expand Up @@ -7,7 +7,7 @@ use futures_util::Stream;
use serde::{Deserialize, Serialize};
use std::{path::PathBuf, pin::Pin, time::SystemTime};
use warg_crypto::{
hash::{DynHash, HashAlgorithm},
hash::{AnyHash, HashAlgorithm},
signing,
};
use warg_protocol::{
Expand Down Expand Up @@ -75,14 +75,14 @@ pub trait ContentStorage: Send + Sync {
/// exists as a file on disk.
///
/// Returns `None` if the content is not present on disk.
fn content_location(&self, digest: &DynHash) -> Option<PathBuf>;
fn content_location(&self, digest: &AnyHash) -> Option<PathBuf>;

/// Loads the content associated with the given digest as a stream.
///
/// If the content is not found, `Ok(None)` is returned.
async fn load_content(
&self,
digest: &DynHash,
digest: &AnyHash,
) -> Result<Option<Pin<Box<dyn Stream<Item = Result<Bytes>> + Send + Sync>>>>;

/// Stores the given stream as content.
Expand All @@ -95,8 +95,8 @@ pub trait ContentStorage: Send + Sync {
async fn store_content(
&self,
stream: Pin<Box<dyn Stream<Item = Result<Bytes>> + Send + Sync>>,
expected_digest: Option<&DynHash>,
) -> Result<DynHash>;
expected_digest: Option<&AnyHash>,
) -> Result<AnyHash>;
}

/// Represents information about a registry operator.
Expand Down Expand Up @@ -144,7 +144,7 @@ pub enum PublishEntry {
/// The version of the release.
version: Version,
/// The content digest of the release.
content: DynHash,
content: AnyHash,
},
}

Expand Down

0 comments on commit 6565977

Please sign in to comment.