16
16
17
17
import Foundation
18
18
19
- #if DEBUG && os(iOS)
19
+ #if DEBUG
20
20
21
21
import MatrixSDKCrypto
22
22
@@ -49,6 +49,7 @@ class MXCryptoMachine {
49
49
case missingVerificationRequest
50
50
case missingVerification
51
51
case missingEmojis
52
+ case missingDecimals
52
53
case cannotCancelVerification
53
54
}
54
55
@@ -313,6 +314,16 @@ extension MXCryptoMachine: MXCryptoUserIdentitySource {
313
314
. keysQuery( requestId: UUID ( ) . uuidString, users: users)
314
315
)
315
316
}
317
+
318
+ func manuallyVerifyUser( userId: String ) async throws {
319
+ let request = try machine. verifyIdentity ( userId: userId)
320
+ try await requests. uploadSignatures ( request: request)
321
+ }
322
+
323
+ func manuallyVerifyDevice( userId: String , deviceId: String ) async throws {
324
+ let request = try machine. verifyDevice ( userId: userId, deviceId: deviceId)
325
+ try await requests. uploadSignatures ( request: request)
326
+ }
316
327
}
317
328
318
329
extension MXCryptoMachine : MXCryptoRoomEventEncrypting {
@@ -355,7 +366,7 @@ extension MXCryptoMachine: MXCryptoRoomEventEncrypting {
355
366
do {
356
367
let decryptedEvent = try machine. decryptRoomEvent ( event: eventString, roomId: roomId)
357
368
let result = try MXEventDecryptionResult ( event: decryptedEvent)
358
- log. debug ( " Successfully decrypted event " )
369
+ log. debug ( " Successfully decrypted event ` \( result . clearEvent [ " type " ] ?? " unknown " ) ` " )
359
370
return result
360
371
361
372
// `Megolm` error does not currently expose the type of "missing keys" error, so have to match against
@@ -464,9 +475,25 @@ extension MXCryptoMachine: MXCryptoCrossSigning {
464
475
requests. uploadSignatures ( request: result. signatureRequest)
465
476
]
466
477
}
478
+
479
+ func exportCrossSigningKeys( ) -> CrossSigningKeyExport ? {
480
+ machine. exportCrossSigningKeys ( )
481
+ }
467
482
}
468
483
469
484
extension MXCryptoMachine : MXCryptoVerificationRequesting {
485
+ func receiveUnencryptedVerificationEvent( event: MXEvent , roomId: String ) {
486
+ guard let string = event. jsonString ( ) else {
487
+ log. failure ( " Invalid event " )
488
+ return
489
+ }
490
+ do {
491
+ try machine. receiveUnencryptedVerificationEvent ( event: string, roomId: roomId)
492
+ } catch {
493
+ log. error ( " Error receiving unencrypted event " , context: error)
494
+ }
495
+ }
496
+
470
497
func requestSelfVerification( methods: [ String ] ) async throws -> VerificationRequest {
471
498
guard let result = try machine. requestSelfVerification ( methods: methods) else {
472
499
throw Error . missingVerification
@@ -502,6 +529,10 @@ extension MXCryptoMachine: MXCryptoVerificationRequesting {
502
529
return request
503
530
}
504
531
532
+ func verificationRequests( userId: String ) -> [ VerificationRequest ] {
533
+ return machine. getVerificationRequests ( userId: userId)
534
+ }
535
+
505
536
func verificationRequest( userId: String , flowId: String ) -> VerificationRequest ? {
506
537
return machine. getVerificationRequest ( userId: userId, flowId: flowId)
507
538
}
@@ -577,6 +608,14 @@ extension MXCryptoMachine: MXCryptoSASVerifying {
577
608
return result. sas
578
609
}
579
610
611
+ func startSasVerification( userId: String , deviceId: String ) async throws -> Sas {
612
+ guard let result = try machine. startSasWithDevice ( userId: userId, deviceId: deviceId) else {
613
+ throw Error . missingVerification
614
+ }
615
+ try await handleOutgoingVerificationRequest ( result. request)
616
+ return result. sas
617
+ }
618
+
580
619
func acceptSasVerification( userId: String , flowId: String ) async throws {
581
620
guard let request = machine. acceptSasVerification ( userId: userId, flowId: flowId) else {
582
621
throw Error . missingVerification
@@ -590,6 +629,38 @@ extension MXCryptoMachine: MXCryptoSASVerifying {
590
629
}
591
630
return indexes. map ( Int . init)
592
631
}
632
+
633
+ func sasDecimals( sas: Sas ) throws -> [ Int ] {
634
+ guard let decimals = machine. getDecimals ( userId: sas. otherUserId, flowId: sas. flowId) else {
635
+ throw Error . missingDecimals
636
+ }
637
+ return decimals. map ( Int . init)
638
+ }
639
+ }
640
+
641
+ extension MXCryptoMachine : MXCryptoQRCodeVerifying {
642
+ func startQrVerification( userId: String , flowId: String ) throws -> QrCode {
643
+ guard let result = try machine. startQrVerification ( userId: userId, flowId: flowId) else {
644
+ throw Error . missingVerification
645
+ }
646
+ return result
647
+ }
648
+
649
+ func scanQrCode( userId: String , flowId: String , data: Data ) async throws -> QrCode {
650
+ let string = MXBase64Tools . base64 ( from: data)
651
+ guard let result = machine. scanQrCode ( userId: userId, flowId: flowId, data: string) else {
652
+ throw Error . missingVerification
653
+ }
654
+ try await handleOutgoingVerificationRequest ( result. request)
655
+ return result. qr
656
+ }
657
+
658
+ func generateQrCode( userId: String , flowId: String ) throws -> Data {
659
+ guard let string = machine. generateQrCode ( userId: userId, flowId: flowId) else {
660
+ throw Error . missingVerification
661
+ }
662
+ return MXBase64Tools . data ( fromBase64: string)
663
+ }
593
664
}
594
665
595
666
extension MXCryptoMachine : MXCryptoBackup {
@@ -667,7 +738,7 @@ extension MXCryptoMachine: MXCryptoBackup {
667
738
guard let json = MXTools . serialiseJSONObject ( jsonKeys) else {
668
739
throw Error . cannotSerialize
669
740
}
670
- return try machine. importDecryptedKeys ( keys: json, progressListener: progressListener)
741
+ return try machine. importDecryptedRoomKeys ( keys: json, progressListener: progressListener)
671
742
}
672
743
}
673
744
0 commit comments