Skip to content

Commit bd149af

Browse files
committed
feat(pbxproj): generate md5 hash
1 parent 2c465af commit bd149af

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ pest = { version = "2.1.3", features = ["pretty-print", "serde
2323
pest_derive = "2.1.0"
2424
pest_consume = "1.1.1"
2525
paste = "1.0.7"
26-
uuid = { version = "1.1.1", features = ["fast-rng", "v4"] }
2726
enum_dispatch = "0.3.8"
2827
enum-as-inner = "0.5.0"
2928
derive_is_enum_variant = "0.1.1"
3029
enum_variant_macros = "0.2.0"
30+
md-5 = "0.10.1"
31+
rand = "0.8.5"
32+
base16ct = "0.1.1"
3133

3234
[dev-dependencies]
3335
tracing-test = "0.2.1"

src/pbxproj/object/collection.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use md5::Digest;
2+
13
use super::*;
24
use std::{
35
cell::RefCell,
@@ -12,15 +14,23 @@ pub type WeakPBXObjectCollection = Weak<RefCell<PBXObjectCollection>>;
1214
#[derive(Default, Debug, derive_new::new, derive_deref_rs::Deref)]
1315
pub struct PBXObjectCollection(pub(crate) HashMap<String, PBXObject>);
1416

17+
use rand::distributions::Alphanumeric;
18+
use rand::{thread_rng, Rng};
19+
1520
/// TODO: make collections a HashSet of PBXObject with identifier included?
1621
impl PBXObjectCollection {
17-
pub(crate) fn set_inner(&mut self, map: HashMap<String, PBXObject>) {
18-
self.0 = map;
19-
}
20-
2122
/// Add new object. same as insert but it auto create id and returns it
2223
pub fn push<O: Into<PBXObject>>(&mut self, object: O) -> String {
23-
let id = uuid::Uuid::new_v4().to_string();
24+
let data: String = thread_rng()
25+
.sample_iter(&Alphanumeric)
26+
.take(20)
27+
.map(char::from)
28+
.collect();
29+
let mut hasher = md5::Md5::new();
30+
let ref mut buf = [0u8; 128];
31+
hasher.update(&data);
32+
let hash = hasher.finalize();
33+
let id = base16ct::upper::encode_str(&hash, buf).unwrap()[..24].to_string();
2434
self.insert(id.clone(), object.into());
2535
id
2636
}
@@ -176,4 +186,8 @@ impl PBXObjectCollection {
176186
.unwrap_or_default()
177187
})
178188
}
189+
190+
pub(crate) fn set_inner(&mut self, map: HashMap<String, PBXObject>) {
191+
self.0 = map;
192+
}
179193
}

src/pbxproj/object/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ mod tests {
456456
"new package should be added to project"
457457
);
458458
let objects = objects.borrow();
459+
println!("{:#?}", objects.build_files());
459460
assert_eq!(
460461
new_package,
461462
objects.swift_package_references().first().unwrap().1,

0 commit comments

Comments
 (0)