eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1import XCTest
2@testable import LChatCore
3
4// Pins the open-group key wire shape shared with the web (shell.js
5// createThread / loadThreads): open_key = {k: <thread key, base64url>}
6// encrypted under the instance key; the group name decrypts with the carried
7// thread key. If either side changes the envelope, this breaks here rather
8// than as a silently-undecryptable directory in production.
9final class OpenKeyRoundTripTests: XCTestCase {
10 func testOpenKeyWireShapeRoundTrips() throws {
11 let ik = try GroupKey(rawKey: ECIES.randomAESKey())
12 let threadRaw = ECIES.randomAESKey()
13
14 // What createChat(openGroup:) writes…
15 let openKey = try ik.encryptJSON(["k": threadRaw.base64urlEncodedString()])
16
17 // …and what the fold / discoverGroups read back.
18 let payload = try ik.decryptJSON(OpenKeyPayload.self, blob: openKey)
19 XCTAssertEqual(Data(base64urlEncoded: payload.k), threadRaw)
20
21 let key = try GroupKey(rawKey: Data(base64urlEncoded: payload.k)!)
22 let nameBlob = try key.encryptJSON(["name": "Fáilte 🏠"])
23 XCTAssertEqual(try key.decryptJSON(GroupNamePayload.self, blob: nameBlob).name, "Fáilte 🏠")
24 }
25}
26