Fix base64 == append

This commit is contained in:
Garth Vander Houwen 2022-10-11 06:02:23 -07:00
parent df57f77686
commit 8cf3520cae
2 changed files with 1 additions and 27 deletions

View file

@ -2,9 +2,6 @@ import Foundation
import SwiftUI
extension Data {
var hexDescription: String {
return reduce("") {$0 + String(format: "%02x", $1)}
}
var macAddressString: String {
let mac: String = reduce("") {$0 + String(format: "%02x:", $1)}
return String(mac.dropLast())
@ -35,31 +32,13 @@ extension Int {
}
extension String {
/// Create `Data` from hexadecimal string representation
///
/// This creates a `Data` object from hex string. Note, if the string has any spaces or non-hex characters (e.g. starts with '<' and with a '>'), those are ignored and only hex characters are processed.
///
/// - returns: Data represented by this hexadecimal string.
var hexadecimal: Data? {
var data = Data(capacity: count / 2)
let regex = try! NSRegularExpression(pattern: "[0-9a-f]{1,2}", options: .caseInsensitive)
regex.enumerateMatches(in: self, range: NSRange(startIndex..., in: self)) { match, _, _ in
let byteString = (self as NSString).substring(with: match!.range)
let num = UInt8(byteString, radix: 16)!
data.append(num)
}
guard data.count > 0 else { return nil }
return data
}
func base64urlToBase64() -> String {
var base64 = self
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
if base64.count % 4 != 0 {
base64.append(String(repeating: "=", count: 4 - base64.count % 4))
base64.append(String(repeating: "==", count: 4 - base64.count % 4))
}
return base64
}

View file

@ -266,9 +266,7 @@ struct ShareChannels: View {
}
}
func GenerateChannelSet() {
channelSet = ChannelSet()
var loRaConfig = Config.LoRaConfig()
loRaConfig.region = RegionCodes(rawValue: Int(node!.loRaConfig!.regionCode))!.protoEnumValue()
loRaConfig.modemPreset = ModemPresets(rawValue: Int(node!.loRaConfig!.modemPreset))!.protoEnumValue()
@ -280,9 +278,7 @@ struct ShareChannels: View {
loRaConfig.txEnabled = node!.loRaConfig!.txEnabled
loRaConfig.txPower = node!.loRaConfig!.txPower
loRaConfig.channelNum = UInt32(node!.loRaConfig!.channelNum)
channelSet.loraConfig = loRaConfig
for ch in node!.myInfo!.channels!.array as! [ChannelEntity] {
if ch.role > 0 {
@ -299,7 +295,6 @@ struct ShareChannels: View {
}
}
}
let settingsString = try! channelSet.serializedData().base64EncodedString()
channelsUrl = ("https://www.meshtastic.org/e/#" + settingsString.base64ToBase64url())
}