Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
feature: [ default, stl, std, alloc, all, secp256k1, curve25519 ]
feature: [ default, stl, std, alloc, ascii-armor, all, secp256k1, curve25519 ]
steps:
- uses: actions/checkout@v2
- name: Install rust stable
Expand Down
19 changes: 16 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ required-features = ["stl"]

[dependencies]
amplify = { version = "4.6.0", default-features = false, features = ["apfloat", "derive", "hex"] }
ascii-armor = { version = "0.2.0", optional = true }
paste = "1"
strict_encoding = { version = "2.7.0-beta.1", default-features = false, features = ["float", "derive"] }
strict_types = { version = "2.7.0-beta.1", optional = true }
Expand All @@ -35,8 +36,8 @@ serde_crate = { package = "serde", version = "1", optional = true }

[features]
default = ["std"]
all = ["stl", "std", "log", "secp256k1", "curve25519", "serde"]
stl = ["strict_types/base85", "std"]
all = ["stl", "std", "log", "secp256k1", "curve25519", "serde", "ascii-armor"]
stl = ["strict_types/armor", "std"]
std = ["amplify/std"]
log = ["std"]
alloc = ["amplify/alloc"]
Expand All @@ -52,4 +53,7 @@ getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = [ "all" ]
features = ["all"]

[patch.crates-io]
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "armor" }
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub mod stl;
mod vm;

pub use isa::Isa;
#[cfg(feature = "ascii-armor")]
pub use library::LibArmorError;
#[doc(hidden)]
pub use paste::paste;
pub use program::{Prog, ProgError, Program};
Expand Down
50 changes: 50 additions & 0 deletions src/library/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use amplify::{ByteArray, Bytes32};
use baid58::{Baid58ParseError, FromBaid58, ToBaid58};
use sha2::{Digest, Sha256};

#[cfg(feature = "ascii-armor")]
pub use self::_armor::LibArmorError;
use super::{Cursor, Read};
use crate::data::ByteStr;
use crate::isa::{Bytecode, BytecodeError, ExecStep, Instr, InstructionSet};
Expand Down Expand Up @@ -168,6 +170,54 @@ impl RustHash for Lib {
fn hash<H: Hasher>(&self, state: &mut H) { state.write(&self.id()[..]) }
}

#[cfg(feature = "ascii-armor")]
mod _armor {
use armor::{ArmorHeader, ArmorParseError, AsciiArmor, ASCII_ARMOR_ID};

use super::*;
use crate::data::encoding::{Decode, DecodeError, Encode};

const ASCII_ARMOR_ISAE: &str = "ISA-Extensions";
const ASCII_ARMOR_DEPENDENCY: &str = "Dependency";

/// Errors while deserializing library from an ASCII Armor.
#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
#[display(inner)]
pub enum LibArmorError {
/// Armor parse error.
#[from]
Armor(ArmorParseError),

/// Library data deserialization error.
#[from]
Decode(DecodeError),
}

impl AsciiArmor for Lib {
type Err = LibArmorError;
const PLATE_TITLE: &'static str = "ALUVM LIB";

fn ascii_armored_headers(&self) -> Vec<ArmorHeader> {
let mut headers = vec![
ArmorHeader::new(ASCII_ARMOR_ID, self.id().to_string()),
ArmorHeader::new(ASCII_ARMOR_ISAE, self.isae.to_string()),
];
for dep in &self.libs {
headers.push(ArmorHeader::new(ASCII_ARMOR_DEPENDENCY, dep.to_string()));
}
headers
}

fn to_ascii_armored_data(&self) -> Vec<u8> { self.serialize() }

fn with_headers_data(_headers: Vec<ArmorHeader>, data: Vec<u8>) -> Result<Self, Self::Err> {
// TODO: check id, dependencies and ISAE
let me = Self::deserialize(data)?;
Ok(me)
}
}
}

/// Errors while assembling library from the instruction set
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, From)]
#[display(inner)]
Expand Down
2 changes: 2 additions & 0 deletions src/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mod rw;
mod segs;

pub use cursor::Cursor;
#[cfg(feature = "ascii-armor")]
pub use lib::LibArmorError;
pub use lib::{AssemblerError, Lib, LibId, LibSite};
pub use rw::{CodeEofError, Read, Write, WriteError};
pub use segs::{IsaSeg, IsaSegError, LibSeg, LibSegOverflow, SegmentError};
4 changes: 2 additions & 2 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----BEGIN STRICT TYPE LIB-----
Id: DVtm25LRKU4TjbyZmVxPhvCmctZ6vKkPKqfpU2QsDNUo#exodus-axiom-tommy
Id: urn:ubideco:stl:DVtm25LRKU4TjbyZmVxPhvCmctZ6vKkPKqfpU2QsDNUo#exodus-axiom-tommy
Name: AluVM
Dependencies: ~
Checksum-SHA256: 225116c3d4fca2a386113db3fd9ffcd2952f3a5e7ea4f1391dd0a6fc139e97ec

1wm|eR!sl^0ssX}X<|ua1pxpD002NB00&HIVpC~!Wd;HRY-wTvr!Z9lE%{u?@QI^
EqCb}2Q7OO^w+`_q*ddTXmHSf)18{G10006
Expand Down