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

Method from_hex

atomic-repository/src/git_binding/codec.rs:133–151  ·  view source on GitHub ↗

Parse from lowercase hex (40 or 64 characters).

(hex: &str)

Source from the content-addressed store, hash-verified

131
132 /// Parse from lowercase hex (40 or 64 characters).
133 pub fn from_hex(hex: &str) -> Result<Self, BindingEncodeError> {
134 match hex.len() {
135 40 => {
136 let bytes = decode_fixed_hex(hex)?;
137 let oid: [u8; 20] = bytes
138 .try_into()
139 .map_err(|_| BindingEncodeError::OidWidth("sha1", hex.len()))?;
140 Ok(GitOid::Sha1(oid))
141 }
142 64 => {
143 let bytes = decode_fixed_hex(hex)?;
144 let oid: [u8; 32] = bytes
145 .try_into()
146 .map_err(|_| BindingEncodeError::OidWidth("sha256", hex.len()))?;
147 Ok(GitOid::Sha256(oid))
148 }
149 _ => Err(BindingEncodeError::OidWidth("hex", hex.len())),
150 }
151 }
152}
153
154fn decode_fixed_hex(hex: &str) -> Result<Vec<u8>, BindingEncodeError> {

Callers

nothing calls this directly

Calls 2

decode_fixed_hexFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected