securegit 0.8.5

Zero-trust git replacement with 12 built-in security scanners, LLM redteam bridge, universal undo, durable backups, and a 50-tool MCP server
Documentation
use anyhow::{bail, Result};

/// An LFS pointer file parsed into its components.
#[derive(Debug, Clone)]
pub struct LfsPointer {
    pub oid: String,
    pub size: u64,
}

const LFS_SIGNATURE: &str = "version https://git-lfs.github.com/spec/";

/// Check if file content is an LFS pointer.
pub fn is_lfs_pointer(content: &[u8]) -> bool {
    if content.len() > 1024 {
        return false; // LFS pointers are small
    }
    if let Ok(text) = std::str::from_utf8(content) {
        text.starts_with(LFS_SIGNATURE)
    } else {
        false
    }
}

/// Parse an LFS pointer file.
pub fn parse_pointer(content: &[u8]) -> Result<LfsPointer> {
    let text = std::str::from_utf8(content)?;

    if !text.starts_with(LFS_SIGNATURE) {
        bail!("Not an LFS pointer file");
    }

    let mut oid = None;
    let mut size = None;

    for line in text.lines() {
        if let Some(rest) = line.strip_prefix("oid sha256:") {
            oid = Some(rest.trim().to_string());
        } else if let Some(rest) = line.strip_prefix("size ") {
            size = Some(rest.trim().parse::<u64>()?);
        }
    }

    match (oid, size) {
        (Some(oid), Some(size)) => Ok(LfsPointer { oid, size }),
        _ => bail!("Invalid LFS pointer: missing oid or size"),
    }
}