Skip to content

Commit 96ee777

Browse files
committed
Deprecate Power enum
Use explict 1.0eNN rather than .tenNN
1 parent 08fe3f0 commit 96ee777

File tree

5 files changed

+8
-24
lines changed

5 files changed

+8
-24
lines changed

EntropyString.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = "EntropyString"
5-
s.version = "2.2.0"
5+
s.version = "2.3.0"
66
s.summary = "Efficiently generate cryptographically strong random strings of specified entropy from various character sets."
77

88
s.description = <<-DESC

Futz.playground/Contents.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

Futz.playground/contents.xcplayground

Lines changed: 0 additions & 4 deletions
This file was deleted.

Sources/Entropy.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ public struct Entropy {
4040
static let bitsPerByte: UInt8 = 8
4141
private static let log2_10: Float = log2(10)
4242

43-
public enum Tmp: UInt {
44-
case one = 1, two, three, four
45-
}
46-
4743
/// Powers of ten
44+
@available(*, deprecated, message: "Use 1.0eNN")
4845
public enum Power: UInt {
4946
case ten01 = 1,
5047
ten02, ten03, ten04, ten05, ten06, ten07, ten08, ten09, ten10, ten11,
@@ -65,7 +62,9 @@ public struct Entropy {
6562
///
6663
/// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
6764
public static func bits(for numStrings: Float , risk: Float) -> Float {
68-
return total(numStrings: numStrings, log2Risk: log2(risk))
65+
guard 0 < numStrings else { return 0 }
66+
let N = numStrings < 10001 ? log2(numStrings) + log2(numStrings-1) : 2 * log2(numStrings)
67+
return N + log2(risk) - 1
6968
}
7069

7170
/// Calculates required bits of entropy
@@ -74,6 +73,7 @@ public struct Entropy {
7473
/// - parameter risk: Accepted probability expressed as 1 in *10^risk* chance of repeat
7574
///
7675
/// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
76+
@available(*, deprecated, message: "Use bits:(Float,Float)")
7777
public static func bits(for numStrings: Float, risk: Power) -> Float {
7878
let log2Risk = Float(risk.rawValue) * log2_10
7979
return total(numStrings: numStrings, log2Risk: log2Risk)
@@ -85,6 +85,7 @@ public struct Entropy {
8585
/// - parameter risk: Accepted probability expressed as 1 in *risk* chance of repeat
8686
///
8787
/// - return: Bits of entropy required to cover the *risk* of repeat in *total* items.
88+
@available(*, deprecated, message: "Use bits:(Float,Float)")
8889
public static func bits(for numStrings: Power, risk: Power) -> Float {
8990
if numStrings < .ten05 {
9091
return bits(for: powf(10, Float(numStrings.rawValue)), risk: risk)
@@ -94,6 +95,7 @@ public struct Entropy {
9495
}
9596
}
9697

98+
// CxTBD Remove with deprecated methods
9799
private static func total(numStrings: Float, log2Risk: Float) -> Float {
98100
guard 0 < numStrings else { return 0 }
99101
let N = numStrings < 10001 ? log2(Float(numStrings)) + log2(Float(numStrings-1)) : 2 * log2(Float(numStrings))

Tests/EntropyStringTests/RandomTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ class RandomTests: XCTestCase {
400400
}
401401
}
402402
}
403-
404403
}
405404

406405
extension RandomTests {

0 commit comments

Comments
 (0)