Skip to main content

gix_object/tag/
mod.rs

1use bstr::ByteSlice;
2
3use crate::parse::parse_signature;
4use crate::{Tag, TagRef};
5
6mod decode;
7
8///
9pub mod write;
10
11///
12pub mod ref_iter;
13
14impl<'a> TagRef<'a> {
15    /// Deserialize a tag from `data`.
16    pub fn from_bytes(mut data: &'a [u8], hash_kind: gix_hash::Kind) -> Result<TagRef<'a>, crate::decode::Error> {
17        let input = &mut data;
18        match decode::git_tag(input, hash_kind) {
19            Ok(tag) => Ok(tag),
20            Err(err) => Err(err),
21        }
22    }
23    /// The object this tag points to as `Id`.
24    pub fn target(&self) -> gix_hash::ObjectId {
25        gix_hash::ObjectId::from_hex(self.target).expect("prior validation")
26    }
27
28    /// Return the tagger, if present.
29    pub fn tagger(&self) -> Result<Option<gix_actor::SignatureRef<'a>>, crate::decode::Error> {
30        Ok(self
31            .tagger
32            .map(parse_signature)
33            .transpose()?
34            .map(|signature| signature.trim()))
35    }
36
37    /// Return the in-body cryptographic signature and its detected format.
38    pub fn signature(&self) -> Option<crate::signature::SignatureRef<'a>> {
39        self.signature.and_then(|data| {
40            crate::signature::Format::from_signature(data).map(|format| crate::signature::SignatureRef { format, data })
41        })
42    }
43
44    /// Copy all data into a fully-owned instance.
45    pub fn into_owned(self) -> Result<crate::Tag, crate::decode::Error> {
46        self.try_into()
47    }
48}
49
50impl Tag {
51    /// Return the in-body cryptographic signature and its detected format.
52    pub fn signature(&self) -> Option<crate::signature::SignatureRef<'_>> {
53        self.signature.as_ref().and_then(|data| {
54            let data = data.as_bstr();
55            crate::signature::Format::from_signature(data).map(|format| crate::signature::SignatureRef { format, data })
56        })
57    }
58}