@@ -25,17 +25,6 @@ public extension Data {
25
25
}
26
26
}
27
27
28
- // func toArray<T>(type: T.Type) throws -> [T] {
29
- // return try self.withUnsafeBytes { (body: UnsafeRawBufferPointer) in
30
- // if let bodyAddress = body.baseAddress, body.count > 0 {
31
- // let pointer = bodyAddress.assumingMemoryBound(to: T.self)
32
- // return [T](UnsafeBufferPointer(start: pointer, count: self.count/MemoryLayout<T>.stride))
33
- // } else {
34
- // throw Web3Error.dataError
35
- // }
36
- // }
37
- // }
38
-
39
28
func constantTimeComparisonTo( _ other: Data ? ) -> Bool {
40
29
guard let rhs = other else { return false }
41
30
guard self . count == rhs. count else { return false }
@@ -53,13 +42,6 @@ public extension Data {
53
42
}
54
43
}
55
44
56
- // static func zero(_ data: inout Data) {
57
- // let count = data.count
58
- // data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) in
59
- // body.baseAddress?.assumingMemoryBound(to: UInt8.self).initialize(repeating: 0, count: count)
60
- // }
61
- // }
62
-
63
45
static func randomBytes( length: Int ) -> Data ? {
64
46
for _ in 0 ... 1024 {
65
47
var data = Data ( repeating: 0 , count: length)
@@ -78,24 +60,6 @@ public extension Data {
78
60
return nil
79
61
}
80
62
81
- // static func randomBytes(length: Int) -> Data? {
82
- // for _ in 0...1024 {
83
- // var data = Data(repeating: 0, count: length)
84
- // let result = data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) -> Int32? in
85
- // if let bodyAddress = body.baseAddress, body.count > 0 {
86
- // let pointer = bodyAddress.assumingMemoryBound(to: UInt8.self)
87
- // return SecRandomCopyBytes(kSecRandomDefault, 32, pointer)
88
- // } else {
89
- // return nil
90
- // }
91
- // }
92
- // if let notNilResult = result, notNilResult == errSecSuccess {
93
- // return data
94
- // }
95
- // }
96
- // return nil
97
- // }
98
-
99
63
static func fromHex( _ hex: String ) -> Data ? {
100
64
let string = hex. lowercased ( ) . stripHexPrefix ( )
101
65
let array = Array < UInt8 > ( hex: string)
@@ -124,20 +88,4 @@ public extension Data {
124
88
uintRepresentation = uintRepresentation >> UInt64 ( 64 - length)
125
89
return uintRepresentation
126
90
}
127
-
128
- // func bitsInRange(_ startingBit: Int, _ length: Int) -> UInt64? { // return max of 8 bytes for simplicity, non-public
129
- // if startingBit + length / 8 > self.count, length > 64, startingBit > 0, length >= 1 {return nil}
130
- // let bytes = self[(startingBit/8) ..< (startingBit+length+7)/8]
131
- // let padding = Data(repeating: 0, count: 8 - bytes.count)
132
- // let padded = bytes + padding
133
- // guard padded.count == 8 else {return nil}
134
- // let pointee = padded.withUnsafeBytes { (body: UnsafeRawBufferPointer) in
135
- // body.baseAddress?.assumingMemoryBound(to: UInt64.self).pointee
136
- // }
137
- // guard let ptee = pointee else {return nil}
138
- // var uintRepresentation = UInt64(bigEndian: ptee)
139
- // uintRepresentation = uintRepresentation << (startingBit % 8)
140
- // uintRepresentation = uintRepresentation >> UInt64(64 - length)
141
- // return uintRepresentation
142
- // }
143
91
}
0 commit comments