Skip to content

Commit 783c91a

Browse files
committed
chore: replace term-painter with bunt
closes #138
1 parent 6bcac64 commit 783c91a

File tree

4 files changed

+77
-131
lines changed

4 files changed

+77
-131
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Secrets can be files for both encoding and decoding #130
66
- **[BREAKING]** `jwt-cli` will always validate `exp` unless you pass `--ignore-exp` #137
7+
- Swapped out [term-painter](https://github.com/LukasKalbertodt/term-painter#when-not-to-use-this-crate) for [bunt](https://crates.io/crates/bunt)
78

89
# 4.0.0
910

Cargo.lock

Lines changed: 47 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test = true
1414
[dependencies]
1515
clap = "2"
1616
jsonwebtoken = "7"
17-
term-painter = "0.3"
17+
bunt = "0.2"
1818
serde = "1"
1919
serde_derive = "1"
2020
serde_json = "1"

src/main.rs

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ use serde_json::{from_str, to_string_pretty, Value};
1111
use std::collections::BTreeMap;
1212
use std::process::exit;
1313
use std::{fs, io};
14-
use term_painter::Attr::*;
15-
use term_painter::Color::*;
16-
use term_painter::ToStyle;
1714

1815
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1916
struct PayloadItem(String, Value);
@@ -534,10 +531,7 @@ fn print_encoded_token(token: JWTResult<String>) {
534531
exit(0);
535532
}
536533
Err(err) => {
537-
eprintln!(
538-
"{}",
539-
Red.bold().paint("Something went awry creating the jwt\n")
540-
);
534+
bunt::eprintln!("{$red+bold}Something went awry creating the jwt{/$}\n");
541535
eprintln!("{}", err);
542536
exit(1);
543537
}
@@ -552,54 +546,38 @@ fn print_decoded_token(
552546
if let Err(err) = &validated_token {
553547
match err.kind() {
554548
ErrorKind::InvalidToken => {
555-
println!("{}", Red.bold().paint("The JWT provided is invalid"))
549+
bunt::println!("{$red+bold}The JWT provided is invalid{/$}")
550+
}
551+
ErrorKind::InvalidSignature => {
552+
bunt::eprintln!("{$red+bold}The JWT provided has an invalid signature{/$}")
553+
}
554+
ErrorKind::InvalidRsaKey => {
555+
bunt::eprintln!("{$red+bold}The secret provided isn't a valid RSA key{/$}")
556+
}
557+
ErrorKind::InvalidEcdsaKey => {
558+
bunt::eprintln!("{$red+bold}The secret provided isn't a valid ECDSA key{/$}")
556559
}
557-
ErrorKind::InvalidSignature => eprintln!(
558-
"{}",
559-
Red.bold()
560-
.paint("The JWT provided has an invalid signature",)
561-
),
562-
ErrorKind::InvalidRsaKey => eprintln!(
563-
"{}",
564-
Red.bold()
565-
.paint("The secret provided isn't a valid RSA key",)
566-
),
567-
ErrorKind::InvalidEcdsaKey => eprintln!(
568-
"{}",
569-
Red.bold()
570-
.paint("The secret provided isn't a valid ECDSA key",)
571-
),
572560
ErrorKind::ExpiredSignature => {
573-
eprintln!("{}", Red.bold().paint("The token has expired (or the `exp` claim is not set). This error can be ignored via the `--ignore-exp` parameter.",))
561+
bunt::eprintln!("{$red+bold}The token has expired (or the `exp` claim is not set). This error can be ignored via the `--ignore-exp` parameter.{/$}")
574562
}
575563
ErrorKind::InvalidIssuer => {
576-
println!("{}", Red.bold().paint("The token issuer is invalid"))
564+
bunt::println!("{$red+bold}The token issuer is invalid{/$}")
577565
}
578-
ErrorKind::InvalidAudience => eprintln!(
579-
"{}",
580-
Red.bold()
581-
.paint("The token audience doesn't match the subject",)
582-
),
583-
ErrorKind::InvalidSubject => eprintln!(
584-
"{}",
585-
Red.bold()
586-
.paint("The token subject doesn't match the audience",)
587-
),
588-
ErrorKind::ImmatureSignature => eprintln!(
589-
"{}",
590-
Red.bold()
591-
.paint("The `nbf` claim is in the future which isn't allowed",)
566+
ErrorKind::InvalidAudience => {
567+
bunt::eprintln!("{$red+bold}The token audience doesn't match the subject{/$}")
568+
}
569+
ErrorKind::InvalidSubject => {
570+
bunt::eprintln!("{$red+bold}The token subject doesn't match the audience{/$}")
571+
}
572+
ErrorKind::ImmatureSignature => bunt::eprintln!(
573+
"{$red+bold}The `nbf` claim is in the future which isn't allowed{/$}"
592574
),
593-
ErrorKind::InvalidAlgorithm => eprintln!(
594-
"{}",
595-
Red.bold().paint(
596-
"The JWT provided has a different signing algorithm than the one you \
597-
provided",
598-
)
575+
ErrorKind::InvalidAlgorithm => bunt::eprintln!(
576+
"{$red+bold}The JWT provided has a different signing algorithm than the one you \
577+
provided{/$}",
599578
),
600-
_ => eprintln!(
601-
"{} {:?}",
602-
Red.bold().paint("The JWT provided is invalid because"),
579+
_ => bunt::eprintln!(
580+
"{$red+bold}The JWT provided is invalid because{/$} {:?}",
603581
err
604582
),
605583
};
@@ -610,9 +588,9 @@ fn print_decoded_token(
610588
println!("{}", to_string_pretty(&TokenOutput::new(token)).unwrap())
611589
}
612590
(_, Ok(token)) => {
613-
println!("\n{}", Plain.bold().paint("Token header\n------------"));
591+
bunt::println!("\n{$bold}Token header\n------------{/$}");
614592
println!("{}\n", to_string_pretty(&token.header).unwrap());
615-
println!("{}", Plain.bold().paint("Token claims\n------------"));
593+
bunt::println!("{$bold}Token claims\n------------{/$}");
616594
println!("{}", to_string_pretty(&token.claims).unwrap());
617595
}
618596
(_, Err(_)) => exit(1),

0 commit comments

Comments
 (0)