use std::ops::Deref;
use ring::digest::Digest;
use crate::{Error, HashKind, error, utils::get_hash};
#[derive(Debug)]
pub struct Tag {
pub hash: Digest,
pub tag: gix_object::Tag,
}
impl Tag {
pub fn parse(data: &[u8], hash_kind: HashKind) -> Result<Self, Error> {
let hash = get_hash("tag", data, hash_kind);
let tag_ref = gix_object::TagRef::from_bytes(data, hash_kind.into())
.map_err(|err| error!("could not parse tag: {err}"))?;
let tag = tag_ref
.into_owned()
.map_err(|err| error!("could not convert tag ref to owned: {err}"))?;
Ok(Self { hash, tag })
}
}
impl Deref for Tag {
type Target = gix_object::Tag;
fn deref(&self) -> &Self::Target {
&self.tag
}
}