Skip to content

Commit 0dc56c4

Browse files
authored
Merge pull request #5 from pkgxdev/contain-the-magic
move the magic strings away
2 parents e603fd9 + e6bda55 commit 0dc56c4

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

Cargo.lock

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

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ I do.
1212

1313
## How to Install
1414

15+
> [!Note]
16+
> This tool is not yet available on `crates.io`. You can install it from source
17+
> below. To change the default keychain service, you can define `BPB_SERVICE_NAME`
18+
> in your environment at build time.
19+
1520
```sh
1621
git clone https://github.com/pkgxdev/bpb
1722
cd bpb
@@ -104,9 +109,4 @@ it does not replace any other functionality. For example, if you want to
104109
verify the signatures on other peoples' git commits, it will shell out to gpg.
105110

106111

107-
## TODO
108-
109-
- [ ] Move keychain identifiers out to build variables in `main.rs`
110-
111-
112112
[teaBASE]: https://github.com/teaxyz/teaBASE

bpb/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ serde_derive = "1.0.215"
1515
serde = "1.0.215"
1616
hex = "0.3.2"
1717
failure = "0.1.1"
18+
lazy_static = "1.5.0"
1819

1920
[dependencies.pbp]
2021
path = "../pbp"

bpb/src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use std::io::{Read, Write};
22

33
use failure::Error;
4+
use lazy_static::lazy_static;
5+
6+
lazy_static! {
7+
static ref SERVICE_NAME: String = option_env!("BPB_SERVICE_NAME")
8+
.unwrap_or("xyz.tea.BASE.bpb")
9+
.to_string();
10+
}
411

512
#[derive(Serialize, Deserialize)]
613
pub struct Config {
@@ -41,6 +48,10 @@ impl Config {
4148
pub fn user_id(&self) -> &str {
4249
&self.public.userid
4350
}
51+
52+
pub fn service(&self) -> &str {
53+
&SERVICE_NAME
54+
}
4455
}
4556

4657
#[derive(Serialize, Deserialize)]

bpb/src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ fn generate_keypair(userid: String) -> Result<(), Error> {
6262
if let Ok(_config) = Config::load() {
6363
eprintln!(
6464
"A keypair already exists. If you (really) want to reinitialize your state\n\
65-
run `security delete-generic-password -s xyz.tea.BASE.bpb` first."
65+
run `security delete-generic-password -s {}` first.",
66+
_config.service()
6667
);
6768
return Ok(());
6869
}
@@ -79,7 +80,7 @@ fn generate_keypair(userid: String) -> Result<(), Error> {
7980
let config = Config::create(public_key, userid, timestamp)?;
8081
config.write()?;
8182

82-
let service = "xyz.tea.BASE.bpb";
83+
let service = config.service();
8384
let account = config.user_id();
8485
let hex = hex::encode(keypair.to_bytes());
8586
add_keychain_item(service, account, &hex)?;
@@ -92,7 +93,7 @@ fn generate_keypair(userid: String) -> Result<(), Error> {
9293

9394
fn print_public_key() -> Result<(), Error> {
9495
let config = Config::load()?;
95-
let service = "xyz.tea.BASE.bpb";
96+
let service = config.service();
9697
let account = config.user_id();
9798
let secret_str = get_keychain_item(service, account)?;
9899
let secret = to_32_bytes(&secret_str)?;
@@ -110,7 +111,7 @@ fn verify_commit() -> Result<(), Error> {
110111
stdin.read_to_string(&mut commit)?;
111112

112113
let config = Config::load()?;
113-
let service = "xyz.tea.BASE.bpb";
114+
let service = config.service();
114115
let account = config.user_id();
115116
let secret_str = get_keychain_item(service, account)?;
116117
let secret = to_32_bytes(&secret_str)?;
@@ -137,7 +138,7 @@ fn delegate() -> ! {
137138
fn upgrade() -> Result<(), Error> {
138139
let mut file = std::fs::File::open(legacy_keys_file())?;
139140
let (config, secret) = LegacyConfig::convert(&mut file)?;
140-
let service = "xyz.tea.BASE.bpb";
141+
let service = config.service();
141142
let account = config.user_id();
142143
let hex = hex::encode(secret);
143144
add_keychain_item(service, account, &hex)?;

0 commit comments

Comments
 (0)