Skip to content

Commit

Permalink
Remove ServiceIdType
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Oct 31, 2024
1 parent 1b55abc commit 0a3940c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 37 deletions.
12 changes: 6 additions & 6 deletions src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hmac::{Hmac, Mac};
use libsignal_protocol::{
kem, Aci, GenericSignedPreKey, IdentityKey, IdentityKeyPair,
IdentityKeyStore, KeyPair, KyberPreKeyRecord, PrivateKey, ProtocolStore,
PublicKey, SenderKeyStore, SignedPreKeyRecord, Timestamp,
PublicKey, SenderKeyStore, ServiceIdKind, SignedPreKeyRecord, Timestamp,
};
use prost::Message;
use serde::{Deserialize, Serialize};
Expand All @@ -30,8 +30,8 @@ use crate::proto::{DeviceName, SyncMessage};
use crate::provisioning::generate_registration_id;
use crate::push_service::{
AvatarWrite, DeviceActivationRequest, DeviceInfo, HttpAuthOverride,
RecaptchaAttributes, RegistrationMethod, ReqwestExt, ServiceIdType,
VerifyAccountResponse, DEFAULT_DEVICE_ID,
RecaptchaAttributes, RegistrationMethod, ReqwestExt, VerifyAccountResponse,
DEFAULT_DEVICE_ID,
};
use crate::sender::OutgoingPushMessage;
use crate::service_address::ServiceIdExt;
Expand Down Expand Up @@ -94,13 +94,13 @@ impl AccountManager {
>(
&mut self,
protocol_store: &mut P,
service_id_type: ServiceIdType,
service_id_kind: ServiceIdKind,
csprng: &mut R,
use_last_resort_key: bool,
) -> Result<(), ServiceError> {
let prekey_status = match self
.service
.get_pre_key_status(service_id_type)
.get_pre_key_status(service_id_kind)
.instrument(tracing::span!(
tracing::Level::DEBUG,
"Fetching pre key status"
Expand Down Expand Up @@ -202,7 +202,7 @@ impl AccountManager {
};

self.service
.register_pre_keys(service_id_type, pre_key_state)
.register_pre_keys(service_id_kind, pre_key_state)
.instrument(tracing::span!(
tracing::Level::DEBUG,
"Uploading pre keys"
Expand Down
21 changes: 0 additions & 21 deletions src/push_service/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,6 @@ use crate::{
utils::{serde_optional_base64, serde_phone_number},
};

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum ServiceIdType {
/// Account Identity (ACI)
///
/// An account UUID without an associated phone number, probably in the future to a username
AccountIdentity,
/// Phone number identity (PNI)
///
/// A UUID associated with a phone number
PhoneNumberIdentity,
}

impl fmt::Display for ServiceIdType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ServiceIdType::AccountIdentity => f.write_str("aci"),
ServiceIdType::PhoneNumberIdentity => f.write_str("pni"),
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ServiceIds {
#[serde(rename = "uuid")]
Expand Down
7 changes: 3 additions & 4 deletions src/push_service/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use aes::cipher::block_padding::UnpadError;
use libsignal_protocol::SignalProtocolError;
use libsignal_protocol::{ServiceIdKind, SignalProtocolError};
use zkgroup::ZkGroupDeserializationFailure;

use crate::groups_v2::GroupDecodingError;

use super::{
MismatchedDevices, ProofRequired, RegistrationLockFailure, ServiceIdType,
StaleDevices,
MismatchedDevices, ProofRequired, RegistrationLockFailure, StaleDevices,
};

#[derive(thiserror::Error, Debug)]
Expand All @@ -18,7 +17,7 @@ pub enum ServiceError {
InvalidUrl(#[from] url::ParseError),

#[error("wrong address type: {0}")]
InvalidAddressType(ServiceIdType),
InvalidAddressType(ServiceIdKind),

#[error("Error sending request: {reason}")]
SendError { reason: String },
Expand Down
12 changes: 6 additions & 6 deletions src/push_service/keys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use libsignal_protocol::{
IdentityKey, PreKeyBundle, SenderCertificate, ServiceId,
IdentityKey, PreKeyBundle, SenderCertificate, ServiceId, ServiceIdKind,
};
use reqwest::Method;
use serde::Deserialize;
Expand All @@ -16,7 +16,7 @@ use crate::{

use super::{
response::ReqwestExt, HttpAuthOverride, PushService, SenderCertificateJson,
ServiceError, ServiceIdType, VerifyAccountResponse,
ServiceError, VerifyAccountResponse,
};

#[derive(Debug, Deserialize, Default)]
Expand All @@ -29,11 +29,11 @@ pub struct PreKeyStatus {
impl PushService {
pub async fn get_pre_key_status(
&mut self,
service_id_type: ServiceIdType,
service_id_kind: ServiceIdKind,
) -> Result<PreKeyStatus, ServiceError> {
self.request(
Method::GET,
Endpoint::service(format!("/v2/keys?identity={}", service_id_type)),
Endpoint::service(format!("/v2/keys?identity={}", service_id_kind)),
HttpAuthOverride::NoOverride,
)?
.send()
Expand All @@ -47,12 +47,12 @@ impl PushService {

pub async fn register_pre_keys(
&mut self,
service_id_type: ServiceIdType,
service_id_kind: ServiceIdKind,
pre_key_state: PreKeyState,
) -> Result<(), ServiceError> {
self.request(
Method::PUT,
Endpoint::service(format!("/v2/keys?identity={}", service_id_type)),
Endpoint::service(format!("/v2/keys?identity={}", service_id_kind)),
HttpAuthOverride::NoOverride,
)?
.json(&pre_key_state)
Expand Down

0 comments on commit 0a3940c

Please sign in to comment.