Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2897649
D12345.id41231.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D12345.id41231.diff
View Options
diff --git a/services/commtest/src/identity/device.rs b/services/commtest/src/identity/device.rs
--- a/services/commtest/src/identity/device.rs
+++ b/services/commtest/src/identity/device.rs
@@ -5,8 +5,7 @@
use rand::{distributions::Alphanumeric, Rng};
use std::borrow::Cow;
-use crate::identity::olm_account_infos::generate_random_olm_key;
-use crate::identity::olm_account_infos::ClientPublicKeys;
+use crate::identity::olm_account::{generate_random_olm_key, ClientPublicKeys};
use crate::service_addr;
use grpc_clients::identity::protos::unauth::{
diff --git a/services/commtest/src/identity/mod.rs b/services/commtest/src/identity/mod.rs
--- a/services/commtest/src/identity/mod.rs
+++ b/services/commtest/src/identity/mod.rs
@@ -1,43 +1,2 @@
-use base64::Engine;
-use ed25519_dalek::{ed25519::signature::Signer, Keypair, Signature};
-use rand::rngs::OsRng;
-
-use self::olm_account_infos::ClientPublicKeys;
-
pub mod device;
-pub mod olm_account_infos;
-
-pub struct MockOlmAccount {
- // primary account ed25519 keypair
- signing_key: Keypair,
-}
-
-impl MockOlmAccount {
- pub fn new() -> Self {
- let mut rng = OsRng {};
- let signing_key = Keypair::generate(&mut rng);
- Self { signing_key }
- }
-
- /// returns device public keys, required for device key upload
- pub fn public_keys(&self) -> ClientPublicKeys {
- let signing_public_key = self.signing_key.public.to_bytes();
- let ed25519 = base64::engine::general_purpose::STANDARD_NO_PAD
- .encode(signing_public_key);
-
- ClientPublicKeys::new(ed25519)
- }
-
- /// signs message, returns signature
- pub fn sign_message(&self, message: &str) -> String {
- let signature: Signature = self.signing_key.sign(message.as_bytes());
- base64::engine::general_purpose::STANDARD_NO_PAD
- .encode(signature.to_bytes())
- }
-}
-
-impl Default for MockOlmAccount {
- fn default() -> Self {
- Self::new()
- }
-}
+pub mod olm_account;
diff --git a/services/commtest/src/identity/olm_account_infos.rs b/services/commtest/src/identity/olm_account.rs
rename from services/commtest/src/identity/olm_account_infos.rs
rename to services/commtest/src/identity/olm_account.rs
--- a/services/commtest/src/identity/olm_account_infos.rs
+++ b/services/commtest/src/identity/olm_account.rs
@@ -1,4 +1,6 @@
-use rand::{distributions::Alphanumeric, Rng};
+use base64::Engine;
+use ed25519_dalek::{ed25519::signature::Signer, Keypair, Signature};
+use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -7,6 +9,7 @@
pub curve25519: String,
}
+/// Represents device's identity key info
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ClientPublicKeys {
@@ -41,6 +44,44 @@
}
}
+/// Struct that simulates Olm account
+pub struct MockOlmAccount {
+ // primary account ed25519 keypair
+ signing_key: Keypair,
+}
+
+impl MockOlmAccount {
+ pub fn new() -> Self {
+ let mut rng = OsRng {};
+ let signing_key = Keypair::generate(&mut rng);
+ Self { signing_key }
+ }
+
+ /// returns device public keys, required for device key upload
+ pub fn public_keys(&self) -> ClientPublicKeys {
+ let signing_public_key = self.signing_key.public.to_bytes();
+ let ed25519 = base64::engine::general_purpose::STANDARD_NO_PAD
+ .encode(signing_public_key);
+
+ ClientPublicKeys::new(ed25519)
+ }
+
+ /// signs message, returns signature
+ pub fn sign_message(&self, message: &str) -> String {
+ let signature: Signature = self.signing_key.sign(message.as_bytes());
+ base64::engine::general_purpose::STANDARD_NO_PAD
+ .encode(signature.to_bytes())
+ }
+}
+
+impl Default for MockOlmAccount {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+/// Generates random 43-character ahlpanumeric string.
+/// It simulates 32-byte (256bit) long base64-encoded data.
pub fn generate_random_olm_key() -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
diff --git a/services/commtest/tests/identity_access_tokens_tests.rs b/services/commtest/tests/identity_access_tokens_tests.rs
--- a/services/commtest/tests/identity_access_tokens_tests.rs
+++ b/services/commtest/tests/identity_access_tokens_tests.rs
@@ -1,7 +1,7 @@
use commtest::identity::device::{
register_user_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION,
};
-use commtest::identity::MockOlmAccount;
+use commtest::identity::olm_account::MockOlmAccount;
use commtest::service_addr;
use grpc_clients::identity::protos::unauth::{
Empty, ExistingDeviceLoginRequest,
diff --git a/services/commtest/tests/identity_device_list_tests.rs b/services/commtest/tests/identity_device_list_tests.rs
--- a/services/commtest/tests/identity_device_list_tests.rs
+++ b/services/commtest/tests/identity_device_list_tests.rs
@@ -6,8 +6,7 @@
login_user_device, logout_user_device, register_user_device,
register_user_device_with_device_list, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION,
};
-use commtest::identity::olm_account_infos::ClientPublicKeys;
-use commtest::identity::MockOlmAccount;
+use commtest::identity::olm_account::{ClientPublicKeys, MockOlmAccount};
use commtest::service_addr;
use grpc_clients::identity::authenticated::ChainedInterceptedAuthClient;
use grpc_clients::identity::protos::auth::{
diff --git a/services/commtest/tests/identity_keyserver_tests.rs b/services/commtest/tests/identity_keyserver_tests.rs
--- a/services/commtest/tests/identity_keyserver_tests.rs
+++ b/services/commtest/tests/identity_keyserver_tests.rs
@@ -1,7 +1,7 @@
use commtest::identity::device::{
register_user_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION,
};
-use commtest::identity::olm_account_infos::generate_random_olm_key;
+use commtest::identity::olm_account::generate_random_olm_key;
use commtest::service_addr;
use grpc_clients::identity::PlatformMetadata;
use grpc_clients::identity::{
diff --git a/services/commtest/tests/identity_one_time_key_tests.rs b/services/commtest/tests/identity_one_time_key_tests.rs
--- a/services/commtest/tests/identity_one_time_key_tests.rs
+++ b/services/commtest/tests/identity_one_time_key_tests.rs
@@ -1,7 +1,7 @@
use commtest::identity::device::{
register_user_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION,
};
-use commtest::identity::olm_account_infos::generate_random_olm_key;
+use commtest::identity::olm_account::generate_random_olm_key;
use commtest::service_addr;
use grpc_clients::identity::PlatformMetadata;
use grpc_clients::identity::{
diff --git a/services/commtest/tests/identity_tunnelbroker_tests.rs b/services/commtest/tests/identity_tunnelbroker_tests.rs
--- a/services/commtest/tests/identity_tunnelbroker_tests.rs
+++ b/services/commtest/tests/identity_tunnelbroker_tests.rs
@@ -1,7 +1,7 @@
use commtest::identity::device::{
register_user_device, DEVICE_TYPE, PLACEHOLDER_CODE_VERSION,
};
-use commtest::identity::olm_account_infos::generate_random_olm_key;
+use commtest::identity::olm_account::generate_random_olm_key;
use commtest::service_addr;
use commtest::tunnelbroker::socket::{create_socket, receive_message};
use futures_util::StreamExt;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 6, 12:07 AM (21 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2245256
Default Alt Text
D12345.id41231.diff (7 KB)
Attached To
Mode
D12345: [commtest] Restructure code into olm_account module
Attached
Detach File
Event Timeline
Log In to Comment