MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / validate_oid

Function validate_oid

atomic-core/src/pristine/ref_mapping.rs:298–313  ·  view source on GitHub ↗

A Git oid field: 40 (SHA-1) or 64 (SHA-256) lowercase hex characters.

(value: Option<&str>)

Source from the content-addressed store, hash-verified

296
297/// A Git oid field: 40 (SHA-1) or 64 (SHA-256) lowercase hex characters.
298fn validate_oid(value: Option<&str>) -> PristineResult<()> {
299 let Some(value) = value else {
300 return Ok(());
301 };
302 let valid_len = value.len() == 40 || value.len() == 64;
303 let hex = value.bytes().all(|b| b.is_ascii_hexdigit())
304 && !value.bytes().any(|b| b.is_ascii_uppercase());
305 if !valid_len || !hex {
306 return Err(PristineError::Serialization {
307 message: format!(
308 "ref mapping oid field is not a 40/64-character lowercase hex Git oid: {value:?}"
309 ),
310 });
311 }
312 Ok(())
313}
314
315/// An Atomic state field: non-empty base32 (the Merkle's base32 encoding).
316fn validate_state(value: Option<&str>) -> PristineResult<()> {

Callers 2

encodeMethod · 0.85
decodeMethod · 0.85

Calls 3

lenMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45

Tested by

no test coverage detected