chore(nix-compat): upgrade to 2024 edition
Part of #114 The lock at `nix-compat/src/nix_daemon/handler.rs:186` gets released later, but this doesnt seem to change behavior. Change-Id: If871a090791740d98bca7a043e86af6a9b0c5463 Reviewed-on: https://cl.snix.dev/c/snix/+/30590 Autosubmit: Bence Nemes <nemes.bence1@gmail.com> Tested-by: besadii Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
parent
f242bc6df8
commit
e8642518f8
44 changed files with 149 additions and 113 deletions
|
|
@ -4070,7 +4070,7 @@ rec {
|
||||||
"nix-compat" = rec {
|
"nix-compat" = rec {
|
||||||
crateName = "nix-compat";
|
crateName = "nix-compat";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
crateBin = [ ];
|
crateBin = [ ];
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
||||||
libName = "nix_compat";
|
libName = "nix_compat";
|
||||||
|
|
@ -4196,7 +4196,7 @@ rec {
|
||||||
"nix-compat-derive" = rec {
|
"nix-compat-derive" = rec {
|
||||||
crateName = "nix-compat-derive";
|
crateName = "nix-compat-derive";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
||||||
procMacro = true;
|
procMacro = true;
|
||||||
libName = "nix_compat_derive";
|
libName = "nix_compat_derive";
|
||||||
|
|
|
||||||
|
|
@ -5503,7 +5503,7 @@ rec {
|
||||||
"nix-compat" = rec {
|
"nix-compat" = rec {
|
||||||
crateName = "nix-compat";
|
crateName = "nix-compat";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
crateBin = [ ];
|
crateBin = [ ];
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
||||||
libName = "nix_compat";
|
libName = "nix_compat";
|
||||||
|
|
@ -5629,7 +5629,7 @@ rec {
|
||||||
"nix-compat-derive" = rec {
|
"nix-compat-derive" = rec {
|
||||||
crateName = "nix-compat-derive";
|
crateName = "nix-compat-derive";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
||||||
procMacro = true;
|
procMacro = true;
|
||||||
libName = "nix_compat_derive";
|
libName = "nix_compat_derive";
|
||||||
|
|
|
||||||
|
|
@ -2797,7 +2797,7 @@ rec {
|
||||||
"nix-compat" = rec {
|
"nix-compat" = rec {
|
||||||
crateName = "nix-compat";
|
crateName = "nix-compat";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
crateBin = [ ];
|
crateBin = [ ];
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
||||||
libName = "nix_compat";
|
libName = "nix_compat";
|
||||||
|
|
@ -2923,7 +2923,7 @@ rec {
|
||||||
"nix-compat-derive" = rec {
|
"nix-compat-derive" = rec {
|
||||||
crateName = "nix-compat-derive";
|
crateName = "nix-compat-derive";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
||||||
procMacro = true;
|
procMacro = true;
|
||||||
libName = "nix_compat_derive";
|
libName = "nix_compat_derive";
|
||||||
|
|
|
||||||
|
|
@ -2879,7 +2879,7 @@ rec {
|
||||||
"nix-compat" = rec {
|
"nix-compat" = rec {
|
||||||
crateName = "nix-compat";
|
crateName = "nix-compat";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
crateBin = [ ];
|
crateBin = [ ];
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat; };
|
||||||
libName = "nix_compat";
|
libName = "nix_compat";
|
||||||
|
|
@ -3005,7 +3005,7 @@ rec {
|
||||||
"nix-compat-derive" = rec {
|
"nix-compat-derive" = rec {
|
||||||
crateName = "nix-compat-derive";
|
crateName = "nix-compat-derive";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ../../snix/nix-compat-derive; };
|
||||||
procMacro = true;
|
procMacro = true;
|
||||||
libName = "nix_compat_derive";
|
libName = "nix_compat_derive";
|
||||||
|
|
|
||||||
|
|
@ -8213,7 +8213,7 @@ rec {
|
||||||
"nix-compat" = rec {
|
"nix-compat" = rec {
|
||||||
crateName = "nix-compat";
|
crateName = "nix-compat";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
crateBin = [
|
crateBin = [
|
||||||
{
|
{
|
||||||
name = "drvfmt";
|
name = "drvfmt";
|
||||||
|
|
@ -8390,7 +8390,7 @@ rec {
|
||||||
"nix-compat-derive" = rec {
|
"nix-compat-derive" = rec {
|
||||||
crateName = "nix-compat-derive";
|
crateName = "nix-compat-derive";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ./nix-compat-derive; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ./nix-compat-derive; };
|
||||||
procMacro = true;
|
procMacro = true;
|
||||||
libName = "nix_compat_derive";
|
libName = "nix_compat_derive";
|
||||||
|
|
@ -8451,7 +8451,7 @@ rec {
|
||||||
"nix-compat-derive-tests" = rec {
|
"nix-compat-derive-tests" = rec {
|
||||||
crateName = "nix-compat-derive-tests";
|
crateName = "nix-compat-derive-tests";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
edition = "2021";
|
edition = "2024";
|
||||||
src = lib.cleanSourceWith { filter = sourceFilter; src = ./nix-compat-derive-tests; };
|
src = lib.cleanSourceWith { filter = sourceFilter; src = ./nix-compat-derive-tests; };
|
||||||
devDependencies = [
|
devDependencies = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nix-compat-derive-tests"
|
name = "nix-compat-derive-tests"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
compile-tests = []
|
compile-tests = []
|
||||||
|
|
|
||||||
2
snix/nix-compat-derive-tests/rustfmt.toml
Normal file
2
snix/nix-compat-derive-tests/rustfmt.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# FUTUREWORK: move to .. once all crates are migrated (#114)
|
||||||
|
edition = "2024"
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use nix_compat::wire::de::mock::{Builder, Error};
|
|
||||||
use nix_compat::wire::de::NixRead;
|
use nix_compat::wire::de::NixRead;
|
||||||
|
use nix_compat::wire::de::mock::{Builder, Error};
|
||||||
use nix_compat_derive::NixDeserialize;
|
use nix_compat_derive::NixDeserialize;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, NixDeserialize)]
|
#[derive(Debug, PartialEq, Eq, NixDeserialize)]
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,7 @@ pub struct Test;
|
||||||
impl FromStr for Test {
|
impl FromStr for Test {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
if s == "test" {
|
if s == "test" { Ok(Test) } else { Err(()) }
|
||||||
Ok(Test)
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,7 @@ impl TryFrom<u64> for Test {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn try_from(value: u64) -> Result<Test, Self::Error> {
|
fn try_from(value: u64) -> Result<Test, Self::Error> {
|
||||||
if value == 42 {
|
if value == 42 { Ok(Test) } else { Err(()) }
|
||||||
Ok(Test)
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use nix_compat::wire::ser::{
|
use nix_compat::wire::ser::{
|
||||||
mock::{Builder, Error},
|
|
||||||
NixWrite as _,
|
NixWrite as _,
|
||||||
|
mock::{Builder, Error},
|
||||||
};
|
};
|
||||||
use nix_compat_derive::NixSerialize;
|
use nix_compat_derive::NixSerialize;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nix-compat-derive"
|
name = "nix-compat-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
|
||||||
2
snix/nix-compat-derive/rustfmt.toml
Normal file
2
snix/nix-compat-derive/rustfmt.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# FUTUREWORK: move to .. once all crates are migrated (#114)
|
||||||
|
edition = "2024"
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::{quote, quote_spanned, ToTokens};
|
use quote::{ToTokens, quote, quote_spanned};
|
||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
use syn::{DeriveInput, Generics, Path, Type};
|
use syn::{DeriveInput, Generics, Path, Type};
|
||||||
|
|
||||||
use crate::internal::attrs::Default;
|
use crate::internal::attrs::Default;
|
||||||
use crate::internal::inputs::RemoteInput;
|
use crate::internal::inputs::RemoteInput;
|
||||||
use crate::internal::{attrs, Container, Context, Data, Field, Remote, Style, Variant};
|
use crate::internal::{Container, Context, Data, Field, Remote, Style, Variant, attrs};
|
||||||
|
|
||||||
pub fn expand_nix_deserialize(
|
pub fn expand_nix_deserialize(
|
||||||
crate_path: Path,
|
crate_path: Path,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::meta::ParseNestedMeta;
|
use syn::meta::ParseNestedMeta;
|
||||||
use syn::parse::Parse;
|
use syn::parse::Parse;
|
||||||
use syn::{parse_quote, Attribute, Expr, ExprLit, ExprPath, Lit, Token};
|
use syn::{Attribute, Expr, ExprLit, ExprPath, Lit, Token, parse_quote};
|
||||||
|
|
||||||
use super::symbol::{
|
|
||||||
Symbol, CRATE, DEFAULT, DISPLAY, FROM, FROM_STR, INTO, NIX, TRY_FROM, TRY_INTO, VERSION,
|
|
||||||
};
|
|
||||||
use super::Context;
|
use super::Context;
|
||||||
|
use super::symbol::{
|
||||||
|
CRATE, DEFAULT, DISPLAY, FROM, FROM_STR, INTO, NIX, Symbol, TRY_FROM, TRY_INTO, VERSION,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Default {
|
pub enum Default {
|
||||||
|
|
@ -209,7 +209,7 @@ pub fn parse_lit<T: Parse>(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use syn::{parse_quote, Attribute};
|
use syn::{Attribute, parse_quote};
|
||||||
|
|
||||||
use crate::internal::Context;
|
use crate::internal::Context;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
use syn::Token;
|
||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
use syn::spanned::Spanned;
|
use syn::spanned::Spanned;
|
||||||
use syn::Token;
|
|
||||||
|
|
||||||
pub mod attrs;
|
pub mod attrs;
|
||||||
mod ctx;
|
mod ctx;
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,7 @@
|
||||||
|
|
||||||
use internal::inputs::RemoteInput;
|
use internal::inputs::RemoteInput;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use syn::{parse_quote, DeriveInput};
|
use syn::{DeriveInput, parse_quote};
|
||||||
|
|
||||||
mod de;
|
mod de;
|
||||||
mod internal;
|
mod internal;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use syn::{DeriveInput, Generics, Path, Type};
|
||||||
|
|
||||||
use crate::internal::attrs::Default;
|
use crate::internal::attrs::Default;
|
||||||
use crate::internal::inputs::RemoteInput;
|
use crate::internal::inputs::RemoteInput;
|
||||||
use crate::internal::{attrs, Container, Context, Data, Field, Remote, Style, Variant};
|
use crate::internal::{Container, Context, Data, Field, Remote, Style, Variant, attrs};
|
||||||
|
|
||||||
pub fn expand_nix_serialize(crate_path: Path, input: &mut DeriveInput) -> syn::Result<TokenStream> {
|
pub fn expand_nix_serialize(crate_path: Path, input: &mut DeriveInput) -> syn::Result<TokenStream> {
|
||||||
let cx = Context::new();
|
let cx = Context::new();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nix-compat"
|
name = "nix-compat"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# async NAR writer. Also needs the `wire` feature.
|
# async NAR writer. Also needs the `wire` feature.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
use nix_compat::derivation::Derivation;
|
use nix_compat::derivation::Derivation;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::{io, str};
|
use std::{io, str};
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
|
use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main};
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
use nix_compat::narinfo::NarInfo;
|
use nix_compat::narinfo::NarInfo;
|
||||||
|
|
||||||
|
|
|
||||||
2
snix/nix-compat/rustfmt.toml
Normal file
2
snix/nix-compat/rustfmt.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# FUTUREWORK: move to .. once all crates are migrated (#114)
|
||||||
|
edition = "2024"
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::store_path::{
|
use crate::store_path::{
|
||||||
self, build_ca_path, build_output_path, build_text_path, StorePath, StorePathRef,
|
self, StorePath, StorePathRef, build_ca_path, build_output_path, build_text_path,
|
||||||
};
|
};
|
||||||
use bstr::BString;
|
use bstr::BString;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,17 @@
|
||||||
//!
|
//!
|
||||||
//! [ATerm]: http://program-transformation.org/Tools/ATermFormat.html
|
//! [ATerm]: http://program-transformation.org/Tools/ATermFormat.html
|
||||||
|
|
||||||
|
use nom::Parser;
|
||||||
use nom::bytes::streaming::tag;
|
use nom::bytes::streaming::tag;
|
||||||
use nom::character::streaming::char as nomchar;
|
use nom::character::streaming::char as nomchar;
|
||||||
use nom::combinator::{all_consuming, consumed, map_res};
|
use nom::combinator::{all_consuming, consumed, map_res};
|
||||||
use nom::multi::{separated_list0, separated_list1};
|
use nom::multi::{separated_list0, separated_list1};
|
||||||
use nom::sequence::{delimited, preceded, separated_pair, terminated};
|
use nom::sequence::{delimited, preceded, separated_pair, terminated};
|
||||||
use nom::Parser;
|
use std::collections::{BTreeMap, BTreeSet, btree_map};
|
||||||
use std::collections::{btree_map, BTreeMap, BTreeSet};
|
|
||||||
use thiserror;
|
use thiserror;
|
||||||
|
|
||||||
use crate::derivation::parse_error::{into_nomerror, ErrorKind, NomError, NomResult};
|
use crate::derivation::parse_error::{ErrorKind, NomError, NomResult, into_nomerror};
|
||||||
use crate::derivation::{write, CAHash, Derivation, Output};
|
use crate::derivation::{CAHash, Derivation, Output, write};
|
||||||
use crate::store_path::{self, StorePath};
|
use crate::store_path::{self, StorePath};
|
||||||
use crate::{aterm, nixhash, nixhash::NixHash};
|
use crate::{aterm, nixhash, nixhash::NixHash};
|
||||||
|
|
||||||
|
|
@ -386,7 +386,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
derivation::{
|
derivation::{
|
||||||
parse_error::ErrorKind, parser::from_algo_and_mode_and_digest, CAHash, NixHash, Output,
|
CAHash, NixHash, Output, parse_error::ErrorKind, parser::from_algo_and_mode_and_digest,
|
||||||
},
|
},
|
||||||
store_path::StorePath,
|
store_path::StorePath,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use super::parse_error::ErrorKind;
|
use super::parse_error::ErrorKind;
|
||||||
|
use crate::derivation::Derivation;
|
||||||
use crate::derivation::output::Output;
|
use crate::derivation::output::Output;
|
||||||
use crate::derivation::parse_error::NomError;
|
use crate::derivation::parse_error::NomError;
|
||||||
use crate::derivation::parser::Error;
|
use crate::derivation::parser::Error;
|
||||||
use crate::derivation::Derivation;
|
|
||||||
use crate::store_path::StorePath;
|
use crate::store_path::StorePath;
|
||||||
use bstr::{BStr, BString};
|
use bstr::{BStr, BString};
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
use crate::aterm::escape_bytes;
|
use crate::aterm::escape_bytes;
|
||||||
use crate::derivation::{ca_kind_prefix, output::Output};
|
use crate::derivation::{ca_kind_prefix, output::Output};
|
||||||
use crate::nixbase32;
|
use crate::nixbase32;
|
||||||
use crate::store_path::{StorePath, STORE_DIR_WITH_SLASH};
|
use crate::store_path::{STORE_DIR_WITH_SLASH, StorePath};
|
||||||
use bstr::BString;
|
use bstr::BString;
|
||||||
use data_encoding::HEXLOWER;
|
use data_encoding::HEXLOWER;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ impl ListingEntry {
|
||||||
match component {
|
match component {
|
||||||
Component::CurDir => continue,
|
Component::CurDir => continue,
|
||||||
Component::RootDir | Component::Prefix(_) | Component::ParentDir => {
|
Component::RootDir | Component::Prefix(_) | Component::ParentDir => {
|
||||||
return Err(ListingError::UnsupportedPathComponent)
|
return Err(ListingError::UnsupportedPathComponent);
|
||||||
}
|
}
|
||||||
Component::Normal(file_or_dir_name) => {
|
Component::Normal(file_or_dir_name) => {
|
||||||
if let Self::Directory { entries } = cur {
|
if let Self::Directory { entries } = cur {
|
||||||
|
|
|
||||||
|
|
@ -202,9 +202,15 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case::wrong_length("cache.nixos.org-1:o1DTsjCz0PofLJ216P2RBuSulI8BAb6zHxWE4N+tzlcELk5Uk/GO2SCxWTRN5wJutLZZ+cHTMdWqOHF8")]
|
#[case::wrong_length(
|
||||||
#[case::wrong_name_newline("test\n:u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw==")]
|
"cache.nixos.org-1:o1DTsjCz0PofLJ216P2RBuSulI8BAb6zHxWE4N+tzlcELk5Uk/GO2SCxWTRN5wJutLZZ+cHTMdWqOHF8"
|
||||||
#[case::wrong_name_space("test :u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw==")]
|
)]
|
||||||
|
#[case::wrong_name_newline(
|
||||||
|
"test\n:u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw=="
|
||||||
|
)]
|
||||||
|
#[case::wrong_name_space(
|
||||||
|
"test :u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw=="
|
||||||
|
)]
|
||||||
#[case::empty_name(
|
#[case::empty_name(
|
||||||
":u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw=="
|
":u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw=="
|
||||||
)]
|
)]
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,18 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case::correct_cache_nixos_org("cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", FINGERPRINT, "cache.nixos.org-1:TsTTb3WGTZKphvYdBHXwo6weVILmTytUjLB+vcX89fOjjRicCHmKA4RCPMVLkj6TMJ4GMX3HPVWRdD1hkeKZBQ==", true)]
|
#[case::correct_cache_nixos_org(
|
||||||
#[case::wrong_name_mismatch("cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=", FINGERPRINT, "cache.nixos.org:TsTTb3WGTZKphvYdBHXwo6weVILmTytUjLB+vcX89fOjjRicCHmKA4RCPMVLkj6TMJ4GMX3HPVWRdD1hkeKZBQ==", false)]
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=",
|
||||||
|
FINGERPRINT,
|
||||||
|
"cache.nixos.org-1:TsTTb3WGTZKphvYdBHXwo6weVILmTytUjLB+vcX89fOjjRicCHmKA4RCPMVLkj6TMJ4GMX3HPVWRdD1hkeKZBQ==",
|
||||||
|
true
|
||||||
|
)]
|
||||||
|
#[case::wrong_name_mismatch(
|
||||||
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=",
|
||||||
|
FINGERPRINT,
|
||||||
|
"cache.nixos.org:TsTTb3WGTZKphvYdBHXwo6weVILmTytUjLB+vcX89fOjjRicCHmKA4RCPMVLkj6TMJ4GMX3HPVWRdD1hkeKZBQ==",
|
||||||
|
false
|
||||||
|
)]
|
||||||
fn verify(
|
fn verify(
|
||||||
#[case] pubkey_str: &'static str,
|
#[case] pubkey_str: &'static str,
|
||||||
#[case] fingerprint: &'static str,
|
#[case] fingerprint: &'static str,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
num::NonZeroU64,
|
num::NonZeroU64,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{self, ready, Poll},
|
task::{self, Poll, ready},
|
||||||
};
|
};
|
||||||
|
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
io::Result,
|
io::Result,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{ready, Poll},
|
task::{Poll, ready},
|
||||||
};
|
};
|
||||||
|
|
||||||
use bytes::{BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
|
|
@ -264,7 +264,7 @@ mod tests {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use tokio::io::{split, AsyncReadExt, BufReader};
|
use tokio::io::{AsyncReadExt, BufReader, split};
|
||||||
use tokio_test::io::Builder;
|
use tokio_test::io::Builder;
|
||||||
|
|
||||||
use crate::{nix_daemon::framing::StderrReadFramedReader, worker_protocol::STDERR_READ};
|
use crate::{nix_daemon::framing::StderrReadFramedReader, worker_protocol::STDERR_READ};
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,24 @@ use std::{future::Future, ops::DerefMut, sync::Arc};
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{split, AsyncReadExt, AsyncWriteExt, ReadHalf, WriteHalf},
|
io::{AsyncReadExt, AsyncWriteExt, ReadHalf, WriteHalf, split},
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
NixDaemonIO,
|
||||||
framing::{NixFramedReader, StderrReadFramedReader},
|
framing::{NixFramedReader, StderrReadFramedReader},
|
||||||
types::{AddToStoreNarRequest, QueryValidPaths},
|
types::{AddToStoreNarRequest, QueryValidPaths},
|
||||||
worker_protocol::{server_handshake_client, ClientSettings, Operation, Trust, STDERR_LAST},
|
worker_protocol::{ClientSettings, Operation, STDERR_LAST, Trust, server_handshake_client},
|
||||||
NixDaemonIO,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
store_path::StorePath,
|
store_path::StorePath,
|
||||||
wire::{
|
wire::{
|
||||||
|
ProtocolVersion,
|
||||||
de::{NixRead, NixReader},
|
de::{NixRead, NixReader},
|
||||||
ser::{NixSerialize, NixWrite, NixWriter, NixWriterBuilder},
|
ser::{NixSerialize, NixWrite, NixWriter, NixWriterBuilder},
|
||||||
ProtocolVersion,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::{nix_daemon::types::QueryValidPaths, store_path::StorePath};
|
use crate::{nix_daemon::types::QueryValidPaths, store_path::StorePath};
|
||||||
|
|
||||||
use super::{types::UnkeyedValidPathInfo, NixDaemonIO};
|
use super::{NixDaemonIO, types::UnkeyedValidPathInfo};
|
||||||
|
|
||||||
// Very simple mock
|
// Very simple mock
|
||||||
// Unable to use mockall as it does not support unboxed async traits.
|
// Unable to use mockall as it does not support unboxed async traits.
|
||||||
|
|
|
||||||
|
|
@ -172,19 +172,27 @@ mod tests {
|
||||||
require_sigs: Some(true),
|
require_sigs: Some(true),
|
||||||
sandbox: Some(SandboxSetting::True),
|
sandbox: Some(SandboxSetting::True),
|
||||||
sandbox_fallback: Some(false),
|
sandbox_fallback: Some(false),
|
||||||
substituters: Some(vec!["https://nix-community.cachix.org", "https://cache.nixos.org/"]),
|
substituters: Some(vec![
|
||||||
|
"https://nix-community.cachix.org",
|
||||||
|
"https://cache.nixos.org/"
|
||||||
|
]),
|
||||||
system_features: Some(vec!["nixos-test", "benchmark", "big-parallel", "kvm"]),
|
system_features: Some(vec!["nixos-test", "benchmark", "big-parallel", "kvm"]),
|
||||||
trusted_public_keys: Some(vec![
|
trusted_public_keys: Some(vec![
|
||||||
VerifyingKey::parse("cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=")
|
VerifyingKey::parse(
|
||||||
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||||
|
)
|
||||||
.expect("failed to parse pubkey"),
|
.expect("failed to parse pubkey"),
|
||||||
VerifyingKey::parse("nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=")
|
VerifyingKey::parse(
|
||||||
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
|
)
|
||||||
.expect("failed to parse pubkey")
|
.expect("failed to parse pubkey")
|
||||||
]),
|
]),
|
||||||
trusted_substituters: Some(vec![]),
|
trusted_substituters: Some(vec![]),
|
||||||
trusted_users: Some(vec!["flokli"]),
|
trusted_users: Some(vec!["flokli"]),
|
||||||
extra_platforms: Some(vec!["aarch64-linux", "i686-linux"]),
|
extra_platforms: Some(vec!["aarch64-linux", "i686-linux"]),
|
||||||
extra_sandbox_paths: Some(vec![
|
extra_sandbox_paths: Some(vec![
|
||||||
"/run/binfmt", "/nix/store/swwyxyqpazzvbwx8bv40z7ih144q841f-qemu-aarch64-binfmt-P-x86_64-unknown-linux-musl"
|
"/run/binfmt",
|
||||||
|
"/nix/store/swwyxyqpazzvbwx8bv40z7ih144q841f-qemu-aarch64-binfmt-P-x86_64-unknown-linux-musl"
|
||||||
]),
|
]),
|
||||||
experimental_features: Some(vec!["nix-command"]),
|
experimental_features: Some(vec!["nix-command"]),
|
||||||
builders_use_substitutes: Some(true)
|
builders_use_substitutes: Some(true)
|
||||||
|
|
|
||||||
|
|
@ -320,8 +320,9 @@ mod tests {
|
||||||
"a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39"
|
"a5ce9c155ed09397614646c9717fc7cd94b1023d7b76b618d409e4fefd6e9d39"
|
||||||
));
|
));
|
||||||
static NIXHASH_SHA512: LazyLock<NixHash> = LazyLock::new(|| {
|
static NIXHASH_SHA512: LazyLock<NixHash> = LazyLock::new(|| {
|
||||||
NixHash::Sha512(Box::new(hex!("ab40d0be3541f0774bba7815d13d10b03252e96e95f7dbb4ee99a3b431c21662fd6971a020160e39848aa5f305b9be0f78727b2b0789e39f124d21e92b8f39ef"))
|
NixHash::Sha512(Box::new(hex!(
|
||||||
)
|
"ab40d0be3541f0774bba7815d13d10b03252e96e95f7dbb4ee99a3b431c21662fd6971a020160e39848aa5f305b9be0f78727b2b0789e39f124d21e92b8f39ef"
|
||||||
|
)))
|
||||||
});
|
});
|
||||||
const NIXHASH_MD5: NixHash = NixHash::Md5(hex!("c4874a8897440b393d862d8fd459073f"));
|
const NIXHASH_MD5: NixHash = NixHash::Md5(hex!("c4874a8897440b393d862d8fd459073f"));
|
||||||
|
|
||||||
|
|
@ -429,17 +430,29 @@ mod tests {
|
||||||
|
|
||||||
/// Test parsing sha512 SRI hash with various paddings, Nix accepts all of them.
|
/// Test parsing sha512 SRI hash with various paddings, Nix accepts all of them.
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case::no_padding("sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ")]
|
#[case::no_padding(
|
||||||
#[case::too_little_padding("sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ=")]
|
"sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ"
|
||||||
#[case::correct_padding("sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ==")]
|
)]
|
||||||
#[case::too_much_padding("sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ===")]
|
#[case::too_little_padding(
|
||||||
#[case::additional_suffix_ignored("sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ== cheesecake")]
|
"sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ="
|
||||||
|
)]
|
||||||
|
#[case::correct_padding(
|
||||||
|
"sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ=="
|
||||||
|
)]
|
||||||
|
#[case::too_much_padding(
|
||||||
|
"sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ==="
|
||||||
|
)]
|
||||||
|
#[case::additional_suffix_ignored(
|
||||||
|
"sha512-7g91TBvYoYQorRTqo+rYD/i5YnWvUBLnqDhPHxBJDaBW7smuPMeRp6E6JOFuVN9bzN0QnH1ToUU0u9c2CjALEQ== cheesecake"
|
||||||
|
)]
|
||||||
fn from_sri_str_sha512_paddings(#[case] sri_str: &str) {
|
fn from_sri_str_sha512_paddings(#[case] sri_str: &str) {
|
||||||
let nix_hash = NixHash::from_sri(sri_str).expect("must succeed");
|
let nix_hash = NixHash::from_sri(sri_str).expect("must succeed");
|
||||||
|
|
||||||
assert_eq!(HashAlgo::Sha512, nix_hash.algo());
|
assert_eq!(HashAlgo::Sha512, nix_hash.algo());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&hex!("ee0f754c1bd8a18428ad14eaa3ead80ff8b96275af5012e7a8384f1f10490da056eec9ae3cc791a7a13a24e16e54df5bccdd109c7d53a14534bbd7360a300b11"),
|
&hex!(
|
||||||
|
"ee0f754c1bd8a18428ad14eaa3ead80ff8b96275af5012e7a8384f1f10490da056eec9ae3cc791a7a13a24e16e54df5bccdd109c7d53a14534bbd7360a300b11"
|
||||||
|
),
|
||||||
nix_hash.digest_as_bytes()
|
nix_hash.digest_as_bytes()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::nixbase32;
|
use crate::nixbase32;
|
||||||
use data_encoding::{DecodeError, BASE64};
|
use data_encoding::{BASE64, DecodeError};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
|
|
@ -341,7 +341,7 @@ mod tests {
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::store_path::{StorePath, StorePathRef, DIGEST_SIZE};
|
use crate::store_path::{DIGEST_SIZE, StorePath, StorePathRef};
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::nixbase32;
|
use crate::nixbase32;
|
||||||
use crate::nixhash::{CAHash, NixHash};
|
use crate::nixhash::{CAHash, NixHash};
|
||||||
use crate::store_path::{Error, StorePath, STORE_DIR};
|
use crate::store_path::{Error, STORE_DIR, StorePath};
|
||||||
use data_encoding::HEXLOWER;
|
use data_encoding::HEXLOWER;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use thiserror;
|
use thiserror;
|
||||||
|
|
@ -85,14 +85,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let (ty, inner_digest) = match &ca_hash {
|
let (ty, inner_digest) = match &ca_hash {
|
||||||
CAHash::Text(ref digest) => (make_references_string("text", references, false), *digest),
|
CAHash::Text(digest) => (make_references_string("text", references, false), *digest),
|
||||||
CAHash::Nar(NixHash::Sha256(ref digest)) => (
|
CAHash::Nar(NixHash::Sha256(digest)) => (
|
||||||
make_references_string("source", references, self_reference),
|
make_references_string("source", references, self_reference),
|
||||||
*digest,
|
*digest,
|
||||||
),
|
),
|
||||||
|
|
||||||
// for all other CAHash::Nar, another custom scheme is used.
|
// for all other CAHash::Nar, another custom scheme is used.
|
||||||
CAHash::Nar(ref hash) => {
|
CAHash::Nar(hash) => {
|
||||||
if references.into_iter().next().is_some() {
|
if references.into_iter().next().is_some() {
|
||||||
return Err(BuildStorePathError::InvalidReference());
|
return Err(BuildStorePathError::InvalidReference());
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@ where
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// CaHash::Flat is using something very similar, except the `r:` prefix.
|
// CaHash::Flat is using something very similar, except the `r:` prefix.
|
||||||
CAHash::Flat(ref hash) => {
|
CAHash::Flat(hash) => {
|
||||||
if references.into_iter().next().is_some() {
|
if references.into_iter().next().is_some() {
|
||||||
return Err(BuildStorePathError::InvalidReference());
|
return Err(BuildStorePathError::InvalidReference());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ where
|
||||||
/// SAFETY: The bytes have to actually be initialized.
|
/// SAFETY: The bytes have to actually be initialized.
|
||||||
#[cfg(feature = "async")]
|
#[cfg(feature = "async")]
|
||||||
unsafe fn assume_init_bytes(slice: &[MaybeUninit<u8>]) -> &[u8] {
|
unsafe fn assume_init_bytes(slice: &[MaybeUninit<u8>]) -> &[u8] {
|
||||||
&*(slice as *const [MaybeUninit<u8>] as *const [u8])
|
unsafe { &*(slice as *const [MaybeUninit<u8>] as *const [u8]) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a "bytes wire packet" of from the AsyncRead and tries to parse as string.
|
/// Read a "bytes wire packet" of from the AsyncRead and tries to parse as string.
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ use std::{
|
||||||
num::NonZeroU64,
|
num::NonZeroU64,
|
||||||
ops::RangeBounds,
|
ops::RangeBounds,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{self, ready, Poll},
|
task::{self, Poll, ready},
|
||||||
};
|
};
|
||||||
use tokio::io::{AsyncBufRead, AsyncRead, AsyncReadExt, ReadBuf};
|
use tokio::io::{AsyncBufRead, AsyncRead, AsyncReadExt, ReadBuf};
|
||||||
|
|
||||||
use trailer::{read_trailer, ReadTrailer, Trailer};
|
use trailer::{ReadTrailer, Trailer, read_trailer};
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use self::trailer::Pad;
|
pub use self::trailer::Pad;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{self, ready, Poll},
|
task::{self, Poll, ready},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio::io::{self, AsyncRead, ReadBuf};
|
use tokio::io::{self, AsyncRead, ReadBuf};
|
||||||
|
|
@ -189,9 +189,11 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn no_padding() {
|
async fn no_padding() {
|
||||||
assert!(read_trailer::<_, Pad>(io::empty(), 0)
|
assert!(
|
||||||
|
read_trailer::<_, Pad>(io::empty(), 0)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is_empty());
|
.is_empty()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use std::task::{ready, Poll};
|
use std::task::{Poll, ready};
|
||||||
|
|
||||||
use tokio::io::AsyncWrite;
|
use tokio::io::AsyncWrite;
|
||||||
|
|
||||||
use super::{padding_len, EMPTY_BYTES, LEN_SIZE};
|
use super::{EMPTY_BYTES, LEN_SIZE, padding_len};
|
||||||
|
|
||||||
pin_project! {
|
pin_project! {
|
||||||
/// Writes a "bytes wire packet" to the underlying writer.
|
/// Writes a "bytes wire packet" to the underlying writer.
|
||||||
|
|
@ -102,10 +102,9 @@ where
|
||||||
BytesPacketPosition::Size(pos) => {
|
BytesPacketPosition::Size(pos) => {
|
||||||
let size_field = &this.payload_len.to_le_bytes();
|
let size_field = &this.payload_len.to_le_bytes();
|
||||||
|
|
||||||
let bytes_written = ensure_nonzero_bytes_written(ready!(this
|
let bytes_written = ensure_nonzero_bytes_written(ready!(
|
||||||
.inner
|
this.inner.as_mut().poll_write(cx, &size_field[pos..])
|
||||||
.as_mut()
|
)?)?;
|
||||||
.poll_write(cx, &size_field[pos..]))?)?;
|
|
||||||
|
|
||||||
let new_pos = pos + bytes_written;
|
let new_pos = pos + bytes_written;
|
||||||
if new_pos == LEN_SIZE {
|
if new_pos == LEN_SIZE {
|
||||||
|
|
@ -138,7 +137,7 @@ where
|
||||||
return Poll::Ready(Err(std::io::Error::new(
|
return Poll::Ready(Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidData,
|
std::io::ErrorKind::InvalidData,
|
||||||
"tried to write excess bytes",
|
"tried to write excess bytes",
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -156,10 +155,9 @@ where
|
||||||
BytesPacketPosition::Size(pos) => {
|
BytesPacketPosition::Size(pos) => {
|
||||||
// More bytes to write in the size field
|
// More bytes to write in the size field
|
||||||
let size_field = &this.payload_len.to_le_bytes()[..];
|
let size_field = &this.payload_len.to_le_bytes()[..];
|
||||||
let bytes_written = ensure_nonzero_bytes_written(ready!(this
|
let bytes_written = ensure_nonzero_bytes_written(ready!(
|
||||||
.inner
|
this.inner.as_mut().poll_write(cx, &size_field[pos..])
|
||||||
.as_mut()
|
)?)?;
|
||||||
.poll_write(cx, &size_field[pos..]))?)?;
|
|
||||||
let new_pos = pos + bytes_written;
|
let new_pos = pos + bytes_written;
|
||||||
if new_pos == LEN_SIZE {
|
if new_pos == LEN_SIZE {
|
||||||
// Size field written, now ready to receive payload
|
// Size field written, now ready to receive payload
|
||||||
|
|
@ -184,10 +182,11 @@ where
|
||||||
let total_padding_len = padding_len(*this.payload_len) as usize;
|
let total_padding_len = padding_len(*this.payload_len) as usize;
|
||||||
|
|
||||||
if pos != total_padding_len {
|
if pos != total_padding_len {
|
||||||
let bytes_written = ensure_nonzero_bytes_written(ready!(this
|
let bytes_written = ensure_nonzero_bytes_written(ready!(
|
||||||
.inner
|
this.inner
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.poll_write(cx, &EMPTY_BYTES[pos..total_padding_len]))?)?;
|
.poll_write(cx, &EMPTY_BYTES[pos..total_padding_len])
|
||||||
|
)?)?;
|
||||||
*this.state = BytesPacketPosition::Padding(pos + bytes_written);
|
*this.state = BytesPacketPosition::Padding(pos + bytes_written);
|
||||||
} else {
|
} else {
|
||||||
// everything written, break
|
// everything written, break
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ use std::future::poll_fn;
|
||||||
use std::io::{self, Cursor};
|
use std::io::{self, Cursor};
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{ready, Context, Poll};
|
use std::task::{Context, Poll, ready};
|
||||||
|
|
||||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use tokio::io::{AsyncBufRead, AsyncRead, AsyncReadExt, ReadBuf};
|
use tokio::io::{AsyncBufRead, AsyncRead, AsyncReadExt, ReadBuf};
|
||||||
|
|
||||||
use crate::wire::{ProtocolVersion, EMPTY_BYTES};
|
use crate::wire::{EMPTY_BYTES, ProtocolVersion};
|
||||||
|
|
||||||
use super::{Error, NixRead};
|
use super::{Error, NixRead};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,7 @@ mod proptest {
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use proptest::{
|
use proptest::{
|
||||||
prelude::{any, Arbitrary, BoxedStrategy, Just, Strategy},
|
prelude::{Arbitrary, BoxedStrategy, Just, Strategy, any},
|
||||||
prop_oneof,
|
prop_oneof,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -487,15 +487,15 @@ mod proptest {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use proptest::prelude::any;
|
|
||||||
use proptest::prelude::TestCaseError;
|
use proptest::prelude::TestCaseError;
|
||||||
|
use proptest::prelude::any;
|
||||||
use proptest::proptest;
|
use proptest::proptest;
|
||||||
|
|
||||||
use crate::wire::ser::mock::proptest::arb_extra_write;
|
|
||||||
use crate::wire::ser::mock::Operation;
|
|
||||||
use crate::wire::ser::mock::OperationType;
|
|
||||||
use crate::wire::ser::Error as _;
|
use crate::wire::ser::Error as _;
|
||||||
use crate::wire::ser::NixWrite;
|
use crate::wire::ser::NixWrite;
|
||||||
|
use crate::wire::ser::mock::Operation;
|
||||||
|
use crate::wire::ser::mock::OperationType;
|
||||||
|
use crate::wire::ser::mock::proptest::arb_extra_write;
|
||||||
|
|
||||||
use super::{Builder, Error};
|
use super::{Builder, Error};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ use std::fmt::{self, Write as _};
|
||||||
use std::future::poll_fn;
|
use std::future::poll_fn;
|
||||||
use std::io::{self, Cursor};
|
use std::io::{self, Cursor};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{ready, Context, Poll};
|
use std::task::{Context, Poll, ready};
|
||||||
|
|
||||||
use bytes::{Buf, BufMut, BytesMut};
|
use bytes::{Buf, BufMut, BytesMut};
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::wire::{padding_len, ProtocolVersion, EMPTY_BYTES};
|
use crate::wire::{EMPTY_BYTES, ProtocolVersion, padding_len};
|
||||||
|
|
||||||
use super::{Error, NixWrite};
|
use super::{Error, NixWrite};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue