Convert from the algorithm-tagged core type.
(object_id: &GitObjectId)
| 85 | impl GitOid { |
| 86 | /// Convert from the algorithm-tagged core type. |
| 87 | pub fn from_git_object_id(object_id: &GitObjectId) -> Result<Self, BindingEncodeError> { |
| 88 | match object_id.algorithm() { |
| 89 | GitHashAlgorithm::Sha1 => { |
| 90 | let bytes: [u8; 20] = object_id.as_bytes().try_into().map_err(|_| { |
| 91 | BindingEncodeError::OidWidth("sha1", object_id.as_bytes().len()) |
| 92 | })?; |
| 93 | Ok(GitOid::Sha1(bytes)) |
| 94 | } |
| 95 | GitHashAlgorithm::Sha256 => { |
| 96 | let bytes: [u8; 32] = object_id.as_bytes().try_into().map_err(|_| { |
| 97 | BindingEncodeError::OidWidth("sha256", object_id.as_bytes().len()) |
| 98 | })?; |
| 99 | Ok(GitOid::Sha256(bytes)) |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /// Convert into the algorithm-tagged core type for Git interop. |
| 105 | pub fn to_git_object_id(&self) -> Result<GitObjectId, BindingEncodeError> { |