summaryrefslogtreecommitdiffstats
path: root/src/options.rs
blob: 8439a0b45c22006316e41146d2ba25c96cf10529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use dua::ByteFormat as LibraryByteFormat;
use std::path::PathBuf;
use structopt::{clap::arg_enum, StructOpt};

arg_enum! {
    #[derive(PartialEq, Debug)]
    pub enum ByteFormat {
        Metric,
        Binary,
        Bytes,
        GB,
        GiB,
        MB,
        MiB
    }
}

impl From<ByteFormat> for LibraryByteFormat {
    fn from(input: ByteFormat) -> Self {
        match input {
            ByteFormat::Metric => LibraryByteFormat::Metric,
            ByteFormat::Binary => LibraryByteFormat::Binary,
            ByteFormat::Bytes => LibraryByteFormat::Bytes,
            ByteFormat::GB => LibraryByteFormat::GB,
            ByteFormat::GiB => LibraryByteFormat::GiB,
            ByteFormat::MB => LibraryByteFormat::MB,
            ByteFormat::MiB => LibraryByteFormat::MiB,
        }
    }
}

#[derive(Debug, StructOpt)]
#[structopt(name = "dua", about = "A tool to learn about disk usage, fast!")]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
pub struct Args {
    #[structopt(subcommand)]
    pub command: Option<Command>,

    /// The amount of threads to use. Defaults to the amount of logical processors.
    /// Set to 1 to use only a single thread.
    #[structopt(short = "t", long = "threads")]
    pub threads: Option<usize>,

    /// The format with which to print byte counts.
    /// Metric - uses 1000 as base (default)
    /// Binary - uses 1024 as base
    /// Bytes - plain bytes without any formatting
    /// GB - only gigabytes
    /// GiB - only gibibytes
    /// MB - only megabytes
    /// MiB - only mebibytes
    #[structopt(short = "f", long)]
    pub format: Option<ByteFormat>,

    /// Display apparent size instead of disk usage.
    #[structopt(short = "A", long)]
    pub apparent_size: bool,

    /// Count hard-linked files each time they are seen
    #[structopt(short = "l", long)]
    pub count_hard_links: bool,

    /// If set, we will not cross filesystems or traverse mount points
    #[structopt(short = "x", long)]
    pub stay_on_filesystem: bool,

    /// One or more input files or directories. If unset, we will use all entries in the current working directory.
    #[structopt(parse(from_os_str))]
    pub input: Vec<PathBuf>,
}

#[derive(Debug, StructOpt)]
pub enum Command {
    /// Launch the terminal user interface
    #[structopt(name = "interactive", visible_alias = "i")]
    Interactive {
        /// One or more input files or directories. If unset, we will use all entries in the current working directory.
        #[structopt(parse(from_os_str))]
        input: Vec<PathBuf>,
    },
    /// Aggregrate the consumed space of one or more directories or files
    #[structopt(name = "aggregate", visible_alias = "a")]
    Aggregate {
        /// If set, print additional statistics about the file traversal to stderr
        #[structopt(long = "stats")]
        statistics: bool,
        /// If set, paths will be printed in their order of occurrence on the command-line.
        /// Otherwise they are sorted by their size in bytes, ascending.
        #[structopt(long)]
        no_sort: bool,
        /// If set, no total column will be computed for multiple inputs
        #[structopt(long)]
        no_total: bool,
        /// One or more input files or directories. If unset, we will use all entries in the current working directory.
        #[structopt(parse(from_os_str))]
        input: Vec<PathBuf>,
    },
}
n class="k">return 0; } } /* Function to configure kernel TLS structure */ int ktls_configure_crypto(const SSL *s, const EVP_CIPHER *c, EVP_CIPHER_CTX *dd, void *rl_sequence, ktls_crypto_info_t *crypto_info, unsigned char **rec_seq, unsigned char *iv, unsigned char *key, unsigned char *mac_key, size_t mac_secret_size) { memset(crypto_info, 0, sizeof(*crypto_info)); switch (s->s3.tmp.new_cipher->algorithm_enc) { case SSL_AES128GCM: case SSL_AES256GCM: crypto_info->cipher_algorithm = CRYPTO_AES_NIST_GCM_16; if (s->version == TLS1_3_VERSION) crypto_info->iv_len = EVP_CIPHER_CTX_get_iv_length(dd); else crypto_info->iv_len = EVP_GCM_TLS_FIXED_IV_LEN; break; case SSL_AES128: case SSL_AES256: switch (s->s3.tmp.new_cipher->algorithm_mac) { case SSL_SHA1: crypto_info->auth_algorithm = CRYPTO_SHA1_HMAC; break; case SSL_SHA256: crypto_info->auth_algorithm = CRYPTO_SHA2_256_HMAC; break; case SSL_SHA384: crypto_info->auth_algorithm = CRYPTO_SHA2_384_HMAC; break; default: return 0; } crypto_info->cipher_algorithm = CRYPTO_AES_CBC; crypto_info->iv_len = EVP_CIPHER_get_iv_length(c); crypto_info->auth_key = mac_key; crypto_info->auth_key_len = mac_secret_size; break; default: return 0; } crypto_info->cipher_key = key; crypto_info->cipher_key_len = EVP_CIPHER_get_key_length(c); crypto_info->iv = iv; crypto_info->tls_vmajor = (s->version >> 8) & 0x000000ff; crypto_info->tls_vminor = (s->version & 0x000000ff); # ifdef TCP_RXTLS_ENABLE memcpy(crypto_info->rec_seq, rl_sequence, sizeof(crypto_info->rec_seq)); if (rec_seq != NULL) *rec_seq = crypto_info->rec_seq; # else if (rec_seq != NULL) *rec_seq = NULL; # endif return 1; }; #endif /* __FreeBSD__ */ #if defined(OPENSSL_SYS_LINUX) /* Function to check supported ciphers in Linux */ int ktls_check_supported_cipher(const SSL *s, const EVP_CIPHER *c, const EVP_CIPHER_CTX *dd) { switch (s->version) { case TLS1_2_VERSION: case TLS1_3_VERSION: break; default: return 0; } /* check that cipher is AES_GCM_128, AES_GCM_256, AES_CCM_128 * or Chacha20-Poly1305 */ switch (EVP_CIPHER_get_nid(c)) { # ifdef OPENSSL_KTLS_AES_CCM_128 case NID_aes_128_ccm: if (s->version == TLS_1_3_VERSION /* broken on 5.x kernels */ || EVP_CIPHER_CTX_get_tag_length(dd) != EVP_CCM_TLS_TAG_LEN) return 0; # endif # ifdef OPENSSL_KTLS_AES_GCM_128 /* Fall through */ case NID_aes_128_gcm: # endif # ifdef OPENSSL_KTLS_AES_GCM_256 case NID_aes_256_gcm: # endif # ifdef OPENSSL_KTLS_CHACHA20_POLY1305 case NID_chacha20_poly1305: # endif return 1; default: return 0; } } /* Function to configure kernel TLS structure */ int ktls_configure_crypto(const SSL *s, const EVP_CIPHER *c, EVP_CIPHER_CTX *dd, void *rl_sequence, ktls_crypto_info_t *crypto_info, unsigned char **rec_seq, unsigned char *iv, unsigned char *key, unsigned char *mac_key, size_t mac_secret_size) { unsigned char geniv[12]; unsigned char *iiv = iv; if (s->version == TLS1_2_VERSION && EVP_CIPHER_get_mode(c) == EVP_CIPH_GCM_MODE) { if (!EVP_CIPHER_CTX_get_updated_iv(dd, geniv, EVP_GCM_TLS_FIXED_IV_LEN + EVP_GCM_TLS_EXPLICIT_IV_LEN)) return 0; iiv = geniv; } memset(crypto_info, 0, sizeof(*crypto_info)); switch (EVP_CIPHER_get_nid(c)) { # ifdef OPENSSL_KTLS_AES_GCM_128 case NID_aes_128_gcm: crypto_info->gcm128.info.cipher_type = TLS_CIPHER_AES_GCM_128; crypto_info->gcm128.info.version = s->version; crypto_info->tls_crypto_info_len = sizeof(crypto_info->gcm128); memcpy(crypto_info->gcm128.iv, iiv + EVP_GCM_TLS_FIXED_IV_LEN, TLS_CIPHER_AES_GCM_128_IV_SIZE); memcpy(crypto_info->gcm128.salt, iiv, TLS_CIPHER_AES_GCM_128_SALT_SIZE); memcpy(crypto_info->gcm128.key, key, EVP_CIPHER_get_key_length(c)); memcpy(crypto_info->gcm128.rec_seq, rl_sequence, TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); if (rec_seq != NULL) *rec_seq = crypto_info->gcm128.rec_seq; return 1; # endif # ifdef OPENSSL_KTLS_AES_GCM_256 case NID_aes_256_gcm: crypto_info->gcm256.info.cipher_type = TLS_CIPHER_AES_GCM_256; crypto_info->gcm256.info.version = s->version; crypto_info->tls_crypto_info_len = sizeof(crypto_info->gcm256); memcpy(crypto_info->gcm256.iv, iiv + EVP_GCM_TLS_FIXED_IV_LEN, TLS_CIPHER_AES_GCM_256_IV_SIZE); memcpy(crypto_info->gcm256.salt, iiv, TLS_CIPHER_AES_GCM_256_SALT_SIZE); memcpy(crypto_info->gcm256.key, key, EVP_CIPHER_get_key_length(c)); memcpy(crypto_info->gcm256.rec_seq, rl_sequence, TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); if (rec_seq != NULL) *rec_seq = crypto_info->gcm256.rec_seq; return 1; # endif # ifdef OPENSSL_KTLS_AES_CCM_128 case NID_aes_128_ccm: crypto_info->ccm128.info.cipher_type = TLS_CIPHER_AES_CCM_128; crypto_info->ccm128.info.version = s->version; crypto_info->tls_crypto_info_len = sizeof(crypto_info->ccm128); memcpy(crypto_info->ccm128.iv, iiv + EVP_CCM_TLS_FIXED_IV_LEN, TLS_CIPHER_AES_CCM_128_IV_SIZE); memcpy(crypto_info->ccm128.salt, iiv, TLS_CIPHER_AES_CCM_128_SALT_SIZE); memcpy(crypto_info->ccm128.key, key, EVP_CIPHER_get_key_length(c)); memcpy(crypto_info->ccm128.rec_seq, rl_sequence, TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); if (rec_seq != NULL) *rec_seq = crypto_info->ccm128.rec_seq; return 1; # endif # ifdef OPENSSL_KTLS_CHACHA20_POLY1305 case NID_chacha20_poly1305: crypto_info->chacha20poly1305.info.cipher_type = TLS_CIPHER_CHACHA20_POLY1305; crypto_info->chacha20poly1305.info.version = s->version; crypto_info->tls_crypto_info_len = sizeof(crypto_info->chacha20poly1305); memcpy(crypto_info->chacha20poly1305.iv, iiv, TLS_CIPHER_CHACHA20_POLY1305_IV_SIZE); memcpy(crypto_info->chacha20poly1305.key, key, EVP_CIPHER_get_key_length(c)); memcpy(crypto_info->chacha20poly1305.rec_seq, rl_sequence, TLS_CIPHER_CHACHA20_POLY1305_REC_SEQ_SIZE); if (rec_seq != NULL) *rec_seq = crypto_info->chacha20poly1305.rec_seq; return 1; # endif default: return 0; } } #endif /* OPENSSL_SYS_LINUX */