-
Notifications
You must be signed in to change notification settings - Fork 28
/
PlatformSpecificTools.mm
40 lines (34 loc) · 1.15 KB
/
PlatformSpecificTools.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import "PlatformSpecificTools.h"
#import <Foundation/Foundation.h>
#import <string>
namespace comm {
void PlatformSpecificTools::generateSecureRandomBytes(
crypto::OlmBuffer &buffer,
size_t size) {
uint8_t randomBytes[size];
const int status = SecRandomCopyBytes(kSecRandomDefault, size, randomBytes);
if (status == errSecSuccess) {
buffer = crypto::OlmBuffer(randomBytes, randomBytes + size);
} else {
throw std::runtime_error(
"SecRandomCopyBytes failed for some reason, error code: " +
std::to_string(status));
}
}
std::string PlatformSpecificTools::getDeviceOS() {
return std::string{"ios"};
}
std::string PlatformSpecificTools::getNotificationsCryptoAccountPath() {
NSURL *groupUrl = [NSFileManager.defaultManager
containerURLForSecurityApplicationGroupIdentifier:@"group.app.comm"];
if (groupUrl == nil) {
throw std::runtime_error(
"Failed to resolve notifications crypto account path - could not find "
"groupUrl");
}
return std::string(
[[groupUrl
URLByAppendingPathComponent:@"comm_notifications_crypto_account"]
.path UTF8String]);
}
}; // namespace comm