Commit e7130b2b authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'min_const_generics' into 'master'

pkgar-core: Use min_const_generics

See merge request !8
parents 081ecf8a 8e65e210
//! The packed structs represent the on-disk format of pkgar
use core::fmt;
use plain::Plain;
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
#[repr(packed)]
pub struct Entry {
/// Blake3 sum of the file data
......@@ -46,46 +44,7 @@ impl Entry {
}
&self.path[..i]
}
/*
pub fn read_at(&self, package: &mut Package, offset: u64, buf: &mut [u8]) -> Result<usize, Error> {
if offset >= self.size {
return Ok(0);
}
let mut end = offset.checked_add(buf.len() as u64)
.ok_or(Error::Overflow)?;
if end > self.size {
end = self.size;
}
let buf_len = usize::try_from(end.checked_sub(offset).unwrap())
.map_err(Error::TryFromInt)?;
package.src.read_at(
// Offset to first entry data
package.header.total_size()?
// Add offset to provided entry data
.checked_add(self.offset)
.ok_or(Error::Overflow)?
// Offset into entry data
.checked_add(offset)
.ok_or(Error::Overflow)?,
&mut buf[..buf_len])
}*/
}
unsafe impl Plain for Entry {}
impl fmt::Debug for Entry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Entry {{\n\tblake3: {:?},\n\toffset: {:?},\n\tsize: {:?},\n\tmode: {:#o},\n\tpath: {:?}\n}}",
self.blake3(),
self.offset(),
self.size(),
self.mode(),
&self.path[..],
)
}
}
//! The packed structs represent the on-disk format of pkgar
use core::convert::TryFrom;
use core::fmt;
use core::mem;
use plain::Plain;
use sodiumoxide::crypto::sign::{self, PublicKey};
use crate::{Entry, Error};
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
#[repr(packed)]
pub struct Header {
/// NaCl signature of header data
......@@ -98,7 +97,7 @@ impl Header {
Ok(plain::slice_from_bytes(data)?)
}
}
/*
impl fmt::Debug for Header {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Header {{\n\tsignature: {:?},\n\tpublic_key: {:?},\n\tblake3: {:?},count: {:?},\n}}",
......@@ -108,5 +107,5 @@ impl fmt::Debug for Header {
self.count(),
)
}
}
}*/
#![no_std]
#![feature(min_const_generics)]
extern crate alloc;
use core::mem;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment