-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Boost]: Reduce dependency on Boost library (#3751)
* [Misc]: Do not use boost/algorithm/string.hpp * [Misc]: Add string.cpp tests * [Misc]: Replace <boost/archive/iterators> * TODO make sure if the changed test covers all cases * [Boost]: Replace <boost/uuid> with a Rust FFI * [Boost]: Minimize the use of <boost/lexical_cast> * [Misc]: Refactor `wallet_core_rs` crate * Remove `tw_proto` test FFIs * [Boost]: Refactor includes * [Boost]: Refactor includes * [Boost]: Minor changes
- Loading branch information
1 parent
adb20c0
commit 2c877a3
Showing
44 changed files
with
181 additions
and
332 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#[cfg(feature = "bitcoin-legacy")] | ||
pub mod legacy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
pub mod uuid_ffi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#![allow(clippy::missing_safety_doc)] | ||
|
||
use std::ffi::{c_char, CString}; | ||
|
||
/// Creates a random UUID. | ||
/// This uses the [`getrandom`] crate to utilise the operating system's RNG | ||
/// as the source of random numbers. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn tw_uuid_random() -> *const c_char { | ||
let res = uuid::Uuid::new_v4(); | ||
CString::new(res.to_string()).unwrap().into_raw() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use std::collections::HashSet; | ||
use std::ffi::CStr; | ||
use wallet_core_rs::ffi::utils::uuid_ffi::tw_uuid_random; | ||
|
||
/// Example of the valid UUID: 3cbbcce1-db89-4ea2-be24-88a686be461c | ||
#[test] | ||
fn test_tw_uuid_random_is_valid() { | ||
let uuid = unsafe { CStr::from_ptr(tw_uuid_random()) } | ||
.to_str() | ||
.unwrap(); | ||
|
||
let tokens: Vec<_> = uuid.split("-").collect(); | ||
assert_eq!(tokens.len(), 5); | ||
assert_eq!(tokens[0].len(), 8); | ||
assert_eq!(tokens[1].len(), 4); | ||
assert_eq!(tokens[2].len(), 4); | ||
assert_eq!(tokens[3].len(), 4); | ||
assert_eq!(tokens[4].len(), 12); | ||
} | ||
|
||
#[test] | ||
fn test_tw_uuid_random_do_not_repeat() { | ||
const ITERATIONS: usize = 10000; | ||
|
||
// Use `Vec` instead of `HashSet` here to make each iteration as fast as possible. | ||
let mut uuids = Vec::with_capacity(ITERATIONS); | ||
for _ in 0..ITERATIONS { | ||
let uuid = unsafe { CStr::from_ptr(tw_uuid_random()) } | ||
.to_str() | ||
.unwrap(); | ||
uuids.push(uuid); | ||
} | ||
|
||
let unique_uuids: HashSet<&str> = uuids.into_iter().collect(); | ||
assert_eq!(unique_uuids.len(), ITERATIONS); | ||
} |
Oops, something went wrong.