diff --git a/src/client.rs b/src/client.rs index 560de302..ba3ff601 100644 --- a/src/client.rs +++ b/src/client.rs @@ -165,6 +165,18 @@ impl Config { } } +impl TryFrom for ConfigFile { + type Error = crate::errors::OciDistributionError; + + fn try_from(config: Config) -> Result { + let config = String::from_utf8(config.data) + .map_err(|e| OciDistributionError::ConfigConversionError(e.to_string()))?; + let config_file: ConfigFile = serde_json::from_str(&config) + .map_err(|e| OciDistributionError::ConfigConversionError(e.to_string()))?; + Ok(config_file) + } +} + /// The OCI client connects to an OCI registry and fetches OCI images. /// /// An OCI registry is a container registry that adheres to the OCI Distribution diff --git a/src/errors.rs b/src/errors.rs index 3404fef8..d7859e45 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -90,6 +90,9 @@ pub enum OciDistributionError { /// Versioned object: JSON deserialization error #[error("Failed to parse manifest: {0}")] VersionedParsingError(String), + #[error("Failed to convert Config into ConfigFile: {0}")] + /// Transparent wrapper around `std::string::FromUtf8Error` + ConfigConversionError(String), } /// Helper type to declare `Result` objects that might return a `OciDistributionError`