p2p-swift / Sources / IrdP2PCrypto / InviteLink.swift
109 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import Foundation

/// Invite links carry the room secret in the URL fragment, which browsers and
/// URL loaders never send to a server.
public enum InviteLink {
    /// `base` with its fragment replaced by the secret, e.g. `myapp://join#<secret>`.
    public static func url(base: URL, secret: RoomSecret) -> URL {
        var comps = URLComponents(url: base, resolvingAgainstBaseURL: false) ?? URLComponents()
        comps.fragment = secret.base64URL
        return comps.url ?? base
    }

    /// The secret in a link's fragment, if it is a valid room secret.
    public static func secret(from url: URL) -> RoomSecret? {
        guard let frag = URLComponents(url: url, resolvingAgainstBaseURL: false)?.fragment, !frag.isEmpty else { return nil }
        return try? RoomSecret(base64URL: frag)
    }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/p2p-swift.git