1use std::ops::Deref;
2
3use ring::digest::Digest;
4
5use crate::{Error, HashKind, error, utils::get_hash};
6
7#[derive(Debug)]
8pub struct Tag {
9 pub hash: Digest,
10 pub tag: gix_object::Tag,
11}
12
13impl Tag {
14 pub fn parse(data: &[u8], hash_kind: HashKind) -> Result<Self, Error> {
20 let hash = get_hash("tag", data, hash_kind);
21 let tag_ref = gix_object::TagRef::from_bytes(data, hash_kind.into())
22 .map_err(|err| error!("could not parse tag: {err}"))?;
23
24 let tag = tag_ref
25 .into_owned()
26 .map_err(|err| error!("could not convert tag ref to owned: {err}"))?;
27
28 Ok(Self { hash, tag })
29 }
30}
31
32impl Deref for Tag {
33 type Target = gix_object::Tag;
34
35 fn deref(&self) -> &Self::Target {
36 &self.tag
37 }
38}