diff --git a/Cargo.lock b/Cargo.lock index f99d91ac..cb1c3665 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,7 +345,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75b8549488b4715defcb0d8a8a1c1c76a80661b5fa106b4ca0e7fce59d7d875" dependencies = [ - "five8_core", + "five8_core 0.1.2", ] [[package]] @@ -354,7 +354,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23f76610e969fa1784327ded240f1e28a3fd9520c9cec93b636fcf62dd37f772" dependencies = [ - "five8_core", + "five8_core 1.0.0", ] [[package]] @@ -363,14 +363,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a0f1728185f277989ca573a402716ae0beaaea3f76a8ff87ef9dd8fb19436c5" dependencies = [ - "five8_core", + "five8_core 1.0.0", ] [[package]] name = "five8_core" -version = "0.1.1" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2551bf44bc5f776c15044b9b94153a00198be06743e262afaaa61f11ac7523a5" + +[[package]] +name = "five8_core" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94474d15a76982be62ca8a39570dccce148d98c238ebb7408b0a21b2c4bdddc4" +checksum = "059c31d7d36c43fe39d89e55711858b4da8be7eb6dabac23c7289b1a19489406" [[package]] name = "fnv" @@ -1069,13 +1075,13 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "solana-account-info" -version = "3.0.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82f4691b69b172c687d218dd2f1f23fc7ea5e9aa79df9ac26dab3d8dd829ce48" +checksum = "a9cf16495d9eb53e3d04e72366a33bb1c20c24e78c171d8b8f5978357b63ae95" dependencies = [ + "solana-address 2.2.0", "solana-program-error", "solana-program-memory", - "solana-pubkey", ] [[package]] @@ -1900,10 +1906,9 @@ dependencies = [ "num-traits", "num_enum", "solana-account-info", - "solana-msg", "solana-program-error", + "solana-zero-copy", "spl-discriminator 0.5.1", - "spl-pod 0.7.2", "spl-type-length-value-derive", "thiserror 2.0.18", ] diff --git a/type-length-value/Cargo.toml b/type-length-value/Cargo.toml index 5e000486..66e5e945 100644 --- a/type-length-value/Cargo.toml +++ b/type-length-value/Cargo.toml @@ -14,15 +14,14 @@ derive = ["dep:spl-type-length-value-derive", "solana-program-error/borsh"] [dependencies] bytemuck = { version = "1.23.2", features = ["derive"] } num-derive = "0.4" -num_enum = "0.7" -num-traits = "0.2" -solana-account-info = "3.0.0" -solana-msg = "3.0.0" +num_enum = { version = "0.7", default-features = false } +num-traits = { version = "0.2", default-features = false } +solana-account-info = "3.1.1" solana-program-error = "3.0.0" +solana-zero-copy = { version = "1.0.0", features = ["bytemuck"] } spl-discriminator = { version = "0.5.1", path = "../discriminator" } spl-type-length-value-derive = { version = "0.2", path = "../type-length-value-derive", optional = true } -spl-pod = { version = "0.7.1", path = "../pod", features = ["bytemuck"] } -thiserror = "2.0" +thiserror = { version = "2.0", default-features = false } [lib] crate-type = ["lib"] diff --git a/type-length-value/src/length.rs b/type-length-value/src/length.rs index 3bab4a26..d3c4bb5a 100644 --- a/type-length-value/src/length.rs +++ b/type-length-value/src/length.rs @@ -2,13 +2,13 @@ use { bytemuck::{Pod, Zeroable}, solana_program_error::ProgramError, - spl_pod::primitives::PodU32, + solana_zero_copy::unaligned::U32, }; /// Length in TLV structure #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] #[repr(transparent)] -pub struct Length(PodU32); +pub struct Length(U32); impl TryFrom for usize { type Error = ProgramError; fn try_from(n: Length) -> Result { @@ -19,7 +19,7 @@ impl TryFrom for Length { type Error = ProgramError; fn try_from(n: usize) -> Result { u32::try_from(n) - .map(|v| Self(PodU32::from(v))) + .map(|v| Self(U32::from(v))) .map_err(|_| ProgramError::AccountDataTooSmall) } } diff --git a/type-length-value/src/lib.rs b/type-length-value/src/lib.rs index 88c9a941..fe5110b9 100644 --- a/type-length-value/src/lib.rs +++ b/type-length-value/src/lib.rs @@ -3,8 +3,11 @@ #![allow(clippy::arithmetic_side_effects)] #![deny(missing_docs)] +#![no_std] #![cfg_attr(not(test), forbid(unsafe_code))] +extern crate alloc; + pub mod error; pub mod length; pub mod state; diff --git a/type-length-value/src/state.rs b/type-length-value/src/state.rs index 6bcbfbfe..3c0ac6cc 100644 --- a/type-length-value/src/state.rs +++ b/type-length-value/src/state.rs @@ -2,14 +2,22 @@ use { crate::{error::TlvError, length::Length, variable_len_pack::VariableLenPack}, - bytemuck::Pod, + alloc::{vec, vec::Vec}, + bytemuck::{try_from_bytes, try_from_bytes_mut, Pod}, + core::{cmp::Ordering, mem::size_of}, solana_account_info::AccountInfo, solana_program_error::ProgramError, spl_discriminator::{ArrayDiscriminator, SplDiscriminate}, - spl_pod::bytemuck::{pod_from_bytes, pod_from_bytes_mut}, - std::{cmp::Ordering, mem::size_of}, }; +fn pod_from_bytes(bytes: &[u8]) -> Result<&T, ProgramError> { + try_from_bytes(bytes).map_err(|_| ProgramError::InvalidArgument) +} + +fn pod_from_bytes_mut(bytes: &mut [u8]) -> Result<&mut T, ProgramError> { + try_from_bytes_mut(bytes).map_err(|_| ProgramError::InvalidArgument) +} + /// Get the current `TlvIndices` from the current spot const fn get_indices_unchecked(type_start: usize, value_repetition_number: usize) -> TlvIndices { let length_start = type_start.saturating_add(size_of::()); @@ -611,6 +619,7 @@ fn check_data(tlv_data: &[u8]) -> Result<(), ProgramError> { mod test { use { super::*, + alloc::string::{String, ToString}, bytemuck::{Pod, Zeroable}, }; @@ -1142,7 +1151,7 @@ mod test { if src[8..8 + length].len() != length { return Err(ProgramError::InvalidAccountData); } - let data = std::str::from_utf8(&src[8..8 + length]) + let data = core::str::from_utf8(&src[8..8 + length]) .unwrap() .to_string(); Ok(Self { data })