[patch.crates-io.possiblyrandom]
path = "possiblyrandom"
-[patch.crates-io]
-bitcoin = { path = "../../rust-bitcoin/bitcoin" }
-bitcoin-io = {path = "../../rust-bitcoin/io" }
-bitcoin_hashes = {path = "../../rust-bitcoin/hashes"}
-
[workspace.lints.rust.unexpected_cfgs]
level = "forbid"
# When adding a new cfg attribute, ensure that it is added to this list.
# Override signing to not include randomness when generating signatures for test vectors.
_test_vectors = []
-no-std = ["hashbrown", "possiblyrandom", "core2/alloc", "libm"]
-std = ["bitcoin/std", "bech32/std", "core2/alloc"]
+no-std = ["hashbrown", "possiblyrandom", "libm"]
+std = ["bech32/std"]
# Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases
grind_signatures = []
regex = { version = "1.5.6", optional = true }
backtrace = { version = "0.3", optional = true }
-core2 = { version = "0.3.0", optional = true, default-features = false }
libm = { version = "0.2", optional = true, default-features = false }
[dev-dependencies]
1 => IntroductionNode::DirectedShortChannelId(Direction::NodeTwo, Readable::read(r)?),
2|3 => {
use io::Read;
- let mut pubkey_read = core::slice::from_mut(&mut first_byte).chain(r.by_ref());
- IntroductionNode::NodeId(Readable::read(&mut pubkey_read)?)
+ let mut bytes = [0; 33];
+ bytes[0] = first_byte;
+ r.read_exact(&mut bytes[1..])?;
+ IntroductionNode::NodeId(Readable::read(&mut &bytes[..])?)
},
_ => return Err(DecodeError::InvalidValue),
};
let mut chacha = ChaCha20Poly1305RFC::new(&secret, &[0; 12], &[]);
let decrypted_len = r.total_bytes() - 16;
- let s = FixedLengthReader::new(&mut r, decrypted_len);
+ let s = FixedLengthReader::new(r, decrypted_len);
let mut chacha_stream = ChaChaPolyReader { chacha: &mut chacha, read: s };
let readable: T = Readable::read(&mut chacha_stream)?;
chacha_stream.read.eat_remaining()?;
// Now deserialize the object back and make sure it matches the original.
let mut read_adapter: Option<ChaChaPolyReadAdapter<TestWriteable>> = None;
- decode_tlv_stream!(&writer.0[..], {
+ decode_tlv_stream!(&mut &writer.0[..], {
(1, read_adapter, (option: LengthReadableArgs, rho)),
});
assert_eq!(writeable, read_adapter.unwrap().readable);
extern crate hex;
#[cfg(any(test, feature = "_test_utils"))] extern crate regex;
-#[cfg(not(feature = "std"))] extern crate core2;
#[cfg(not(feature = "std"))] extern crate libm;
#[cfg(ldk_bench)] extern crate criterion;
Ok(count)
}
- pub fn read_to_end<D: Read>(mut d: D) -> Result<alloc::vec::Vec<u8>, io::Error> {
+ pub fn read_to_end<D: Read>(mut d: &mut D) -> Result<alloc::vec::Vec<u8>, io::Error> {
let mut result = vec![];
let mut buf = [0u8; 64];
loop {
let mut custom_tlvs = Vec::new();
let tlv_len = BigSize::read(r)?;
- let rd = FixedLengthReader::new(r, tlv_len.0);
- decode_tlv_stream_with_custom_tlv_decode!(rd, {
+ let mut rd = FixedLengthReader::new(r, tlv_len.0);
+ decode_tlv_stream_with_custom_tlv_decode!(&mut rd, {
(2, amt, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
(4, cltv_value, (option, encoding: (u32, HighZeroBytesDroppedBigSize))),
(6, short_id, option),
pub(crate) fn read_graph_scorer(logger: &TestLogger)
-> Result<(Arc<NetworkGraph<&TestLogger>>, ProbabilisticScorer<Arc<NetworkGraph<&TestLogger>>, &TestLogger>), &'static str> {
let (mut graph_file, mut scorer_file) = get_graph_scorer_file()?;
- let graph = Arc::new(NetworkGraph::read(&mut graph_file, logger).unwrap());
+ let graph = Arc::new(NetworkGraph::read(&mut std::io::BufReader::new(graph_file), logger).unwrap());
let scorer_args = (Default::default(), Arc::clone(&graph), logger);
- let scorer = ProbabilisticScorer::read(&mut scorer_file, scorer_args).unwrap();
+ let scorer = ProbabilisticScorer::read(&mut std::io::BufReader::new(scorer_file), scorer_args).unwrap();
Ok((graph, scorer))
}
}
// pub(crate) struct ReadBufReadAdapter<R: Read + ?Sized>(pub R);
-pub struct BufReader<R, const S: usize> {
- inner: R,
+pub struct BufReader<'a, R, const S: usize = 4096> {
+ inner: &'a mut R,
buf: [u8; S],
pos: usize,
cap: usize,
}
-impl<R: Read, const S: usize> BufReader<R, S> {
- pub fn new(inner: R) -> BufReader<R, S> {
+impl<'a, R: Read, const S: usize> BufReader<'a, R, S> {
+ pub fn new(inner: &'a mut R) -> BufReader<'a, R, S> {
BufReader {
inner,
buf: [0; S],
}
}
-impl<R: Read, const S: usize> Read for BufReader<R, S> {
+impl<'a, R: Read, const S: usize> Read for BufReader<'a, R, S> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
// If we don't have any buffered data and we're doing a massive read
// (larger than our internal buffer), bypass our internal buffer
// entirely.
if self.pos == self.cap && buf.len() >= S {
- self.discard_buffer();
+ //self.discard_buffer();
return self.inner.read(buf);
}
let nread = {
}
}
-impl<R: Read, const S: usize> BufRead for BufReader<R, S> {
+impl<'a, R: Read, const S: usize> BufRead for BufReader<'a, R, S> {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
// If we've reached the end of our internal buffer then we need to fetch
// some more data from the underlying reader.
/// between "EOF reached before we started" and "EOF reached mid-read".
///
/// This is not exported to bindings users as manual TLV building is not currently supported in bindings
-pub struct ReadTrackingReader<R: Read> {
- read: R,
+pub struct ReadTrackingReader<'a, R: Read> {
+ read: &'a mut R,
/// Returns whether we have read from this reader or not yet.
pub have_read: bool,
}
-impl<R: Read> ReadTrackingReader<R> {
+impl<'a, R: Read> ReadTrackingReader<'a, R> {
/// Returns a new [`ReadTrackingReader`].
- pub fn new(read: R) -> Self {
+ pub fn new(read: &'a mut R) -> Self {
Self { read, have_read: false }
}
}
-impl<R: Read> Read for ReadTrackingReader<R> {
+impl<'a, R: Read> Read for ReadTrackingReader<'a, R> {
#[inline]
fn read(&mut self, dest: &mut [u8]) -> Result<usize, io::Error> {
match self.read.read(dest) {
fn read<R: Read>(mut reader: &mut R) -> Result<Self, DecodeError> {
let mut values = Vec::new();
loop {
- let mut track_read = ReadTrackingReader::new(&mut reader);
+ let mut track_read = ReadTrackingReader::new(reader);
match MaybeReadable::read(&mut track_read) {
Ok(Some(v)) => { values.push(v); },
Ok(None) => { },
impl Readable for $bitcoin_type {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
- match consensus::encode::Decodable::consensus_decode(&mut BufReader::new(r)) {
+ match consensus::encode::Decodable::consensus_decode(&mut BufReader::<_, 4096>::new(r)) {
Ok(t) => Ok(t),
Err(consensus::encode::Error::Io(ref e)) if e.kind() == io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead),
Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind().into())),
// determine whether we should break or return ShortRead if we get an
// UnexpectedEof. This should in every case be largely cosmetic, but its nice to
// pass the TLV test vectors exactly, which require this distinction.
- let mut tracking_reader = ser::ReadTrackingReader::new(&mut stream_ref);
+ let mut tracking_reader = ser::ReadTrackingReader::new(stream_ref);
match <$crate::util::ser::BigSize as $crate::util::ser::Readable>::read(&mut tracking_reader) {
Err(DecodeError::ShortRead) => {
if !tracking_reader.have_read {
last_seen_type = Some(typ.0);
// Finally, read the length and value itself:
- let length: ser::BigSize = $crate::util::ser::Readable::read(&mut stream_ref)?;
- let mut s = ser::FixedLengthReader::new(&mut stream_ref, length.0);
+ let length: ser::BigSize = $crate::util::ser::Readable::read(stream_ref)?;
+ let mut s = ser::FixedLengthReader::new(stream_ref, length.0);
match typ.0 {
$(_t if $crate::_decode_tlv_stream_match_check!(_t, $type, $fieldty) => {
$crate::_decode_tlv!($stream, s, $field, $fieldty);
}),*
$($tuple_variant_id => {
let length: $crate::util::ser::BigSize = $crate::util::ser::Readable::read(reader)?;
- let mut s = $crate::util::ser::FixedLengthReader::new(&mut reader, length.0);
+ let mut s = $crate::util::ser::FixedLengthReader::new(reader, length.0);
let res = $crate::util::ser::Readable::read(&mut s)?;
if s.bytes_remain() {
s.eat_remaining()?; // Return ShortRead if there's actually not enough bytes
}),*
$($tuple_variant_id => {
let length: $crate::util::ser::BigSize = $crate::util::ser::Readable::read(reader)?;
- let mut s = $crate::util::ser::FixedLengthReader::new(&mut reader, length.0);
+ let mut s = $crate::util::ser::FixedLengthReader::new(reader, length.0);
let res = $crate::util::ser::Readable::read(&mut s)?;
if s.bytes_remain() {
s.eat_remaining()?; // Return ShortRead if there's actually not enough bytes