Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulled CLI tools into a single crate and consolidated. #8

Merged
merged 8 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
261 changes: 131 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"zvt",
"zvt_builder",
"zvt_cli",
"zvt_derive",
]

Expand Down
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crates_repository(
"//:Cargo.toml",
"//zvt:Cargo.toml",
"//zvt_builder:Cargo.toml",
"//zvt_cli:Cargo.toml",
"//zvt_derive:Cargo.toml",
],
)
Expand Down
19 changes: 1 addition & 18 deletions zvt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@ load("@crate_index//:defs.bzl", "all_crate_deps")

rust_library(
name = "zvt",
srcs = glob(
["src/**/*.rs"],
exclude = ["src/main.rs"],
),
srcs = glob(["src/**/*.rs"]),
crate_name = "zvt",
edition = "2021",
proc_macro_deps = all_crate_deps(proc_macro = True) + ["//zvt_derive"],
visibility = ["//visibility:public"],
deps = all_crate_deps() + ["//zvt_builder"],
)

rust_binary(
name = "status",
srcs = glob(["src/bin/status/main.rs"]),
edition = "2021",
deps = all_crate_deps() + [":zvt"],
)

rust_binary(
name = "feig_update",
srcs = glob(["src/bin/feig_update/main.rs"]),
edition = "2021",
deps = all_crate_deps() + [":zvt"],
)

rust_test(
name = "zvt_test",
srcs = [],
Expand Down
17 changes: 6 additions & 11 deletions zvt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ A crate to interact with payment terminals (ECRs) that use the ZVT protocol, inc

[dependencies]
anyhow = "1.0.70"
async-stream = "0.3.5"
chrono = "0.4.24"
clap = { version = "4.2.4", features = ["derive"] }
hex = "0.4.3"
yore = "1.0.2"
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
futures = "0.3.28"
log = "0.4.19"
env_logger = "0.10.0"
tokio-stream = "0.1.14"
pretty-hex = "0.4.0"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
async-stream = "0.3.5"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
futures = "0.3.28"
tokio-stream = "0.1.14"
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
158 changes: 0 additions & 158 deletions zvt/src/bin/status/main.rs

This file was deleted.

11 changes: 10 additions & 1 deletion zvt/src/feig/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ pub struct WriteFile {
#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x0f, instr = 0xa1)]
pub struct CVendFunctions {
#[zvt_bmp(length = length::Fixed<3>, encoding = encoding::Bcd)]
pub password: Option<usize>,
SirVer marked this conversation as resolved.
Show resolved Hide resolved

#[zvt_bmp( encoding = encoding::BigEndian)]
pub instr: u16,
}

pub const CVEND_FUNCTIONS_ENHANCED_SYSTEMS_INFO: u16 = 1;
SirVer marked this conversation as resolved.
Show resolved Hide resolved
pub const CVEND_FUNCTIONS_ENHANCED_FACTORY_RESET: u16 = 0x0255;

#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x80, instr = 0x00)]
pub struct WriteData {
Expand Down Expand Up @@ -192,7 +198,10 @@ mod test {
#[test]
fn test_cvend_functions() {
let bytes = get_bytes("1680761818.690979000_ecr_pt.blob");
let expected = CVendFunctions { instr: 0x01 };
let expected = CVendFunctions {
password: None,
instr: 0x01,
};
assert_eq!(CVendFunctions::zvt_deserialize(&bytes).unwrap().0, expected);
assert_eq!(bytes, expected.zvt_serialize());
}
Expand Down
12 changes: 12 additions & 0 deletions zvt/src/feig/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,15 @@ impl WriteFile {
Box::pin(s)
}
}

pub struct FactoryReset;

#[derive(Debug, ZvtEnum)]
pub enum FactoryResetResponse {
SirVer marked this conversation as resolved.
Show resolved Hide resolved
CompletionData(packets::CompletionData),
}

impl Sequence for FactoryReset {
type Input = super::packets::CVendFunctions;
type Output = FactoryResetResponse;
}
1 change: 1 addition & 0 deletions zvt/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ where
buf.resize(start + len, 0);
self.source.read_exact(&mut buf[start..]).await?;

// NOCOM(#sirver): add pretty hex here
SirVer marked this conversation as resolved.
Show resolved Hide resolved
log::debug!("Read {:?}", buf);

Ok(T::zvt_parse(&buf)?)
Expand Down
10 changes: 10 additions & 0 deletions zvt/src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ pub struct Diagnosis {
pub tlv: Option<tlv::Diagnosis>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum DiagnosisType {
Line = 1,
Extended = 2,
Configuration = 3,
EmvConfiguration = 4,
Ep2Configuration = 5,
}

#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x06, instr = 0x93)]
pub struct Initialization {
Expand Down
16 changes: 16 additions & 0 deletions zvt_cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("@crate_index//:defs.bzl", "all_crate_deps")

rust_binary(
name = "zvt_cli",
srcs = glob(["src/main.rs"]),
edition = "2021",
deps = all_crate_deps() + ["//zvt"],
)

rust_binary(
name = "feig_update",
srcs = glob(["src/bin/feig_update/main.rs"]),
edition = "2021",
deps = all_crate_deps() + ["//zvt"],
)
23 changes: 23 additions & 0 deletions zvt_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "zvt_cli"
edition = "2021"
authors.workspace = true
categories.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true
description = """
A crate to interact with payment terminals (ECRs) that use the ZVT protocol, including stand alone commandline tools to interact with the devices.
"""

[dependencies]
anyhow = "1.0.70"
argh = "0.1.12"
env_logger = "0.10.0"
log = "0.4.19"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.14"
zvt = { version = "0.1.0", path = "../zvt" }
Loading