Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
m00sey committed Feb 2, 2023
1 parent 0eedc49 commit 112ce40
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 181 deletions.
41 changes: 18 additions & 23 deletions src/core/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Default for Indexer {
fn default() -> Self {
Indexer {
raw: vec![],
code: tables::Codex::Ed25519_Sig.code().to_string(),
code: tables::Codex::Ed25519.code().to_string(),
index: 0,
ondex: Some(u32::MAX),
}
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Indexer {
}

if let Some(o) = ondex {
if szg.os > 0 && !(o <= SIXTY_FOUR.pow(szg.os - 1)) {
if szg.os > 0 && o > SIXTY_FOUR.pow(szg.os - 1) {
return Err(Box::new(Error::InvalidVarIndex(format!(
"Invalid ondex '{o}' for code '{code}'"
))));
Expand All @@ -84,19 +84,16 @@ impl Indexer {
// when not provided make ondex match index
ondex = Some(index);
}
} else {
if let Some(o) = ondex {
if o != index && szg.os == 0 {
return Err(Box::new(Error::InvalidVarIndex(format!(
"Non matching ondex '{o}' and index '{index}' for code = '{code}'."
))));
}
} else if let Some(o) = ondex {
if o != index && szg.os == 0 {
return Err(Box::new(Error::InvalidVarIndex(format!(
"Non matching ondex '{o}' and index '{index}' for code = '{code}'."
))));
}
}

// compute fs from index
let fs;
if szg.fs == u32::MAX {
let fs = if szg.fs == u32::MAX {
if cs % 4 != 0 {
return Err(Box::new(Error::InvalidCodeSize(format!(
"Whole code size not multiple of 4 for variable length material. cs = '{cs}'."
Expand All @@ -110,9 +107,9 @@ impl Indexer {
))));
}

fs = (index * 4) + cs
(index * 4) + cs
} else {
fs = szg.fs;
szg.fs
};

let raw_size = (fs - cs) * 3 / 4;
Expand All @@ -127,8 +124,8 @@ impl Indexer {
Ok(Indexer {
code,
raw: raw.to_vec(),
index: index,
ondex: ondex,
index,
ondex,
})
}

Expand All @@ -147,7 +144,7 @@ impl Indexer {
}

pub fn new_with_qb2(qb2: &[u8]) -> Result<Indexer> {
let mut i: Indexer = Default::default();
let i: Indexer = Default::default();
i.bexfil(qb2)?;
Ok(i)
}
Expand Down Expand Up @@ -195,12 +192,10 @@ impl Indexer {
o = ondex.unwrap()
))));
}
} else if szg.os != 0 {
ondex = Some(util::b64_to_u32(odx)?);
} else {
if szg.os != 0 {
ondex = Some(util::b64_to_u32(odx)?);
} else {
ondex = Some(index);
}
ondex = Some(index);
}

// index is index for some codes and variable length for others
Expand Down Expand Up @@ -283,14 +278,14 @@ impl Indexer {
Ok(())
}

fn bexfil(&self, qb2: &[u8]) -> Result<()> {
fn bexfil(&self, _qb2: &[u8]) -> Result<()> {
todo!()
}
}

#[cfg(test)]
mod indexer_tests {
use crate::core::indexer::Indexer;


#[test]
fn test_indexer_new() {
Expand Down
Loading

0 comments on commit 112ce40

Please sign in to comment.