Skip to content

Commit

Permalink
fix: internal protection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sammous committed Sep 11, 2022
1 parent e315eb4 commit b9788be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ It includes several methods:
```swift
import Xenissuing

do {
let xenKey = Data(base64EncodedString: "BASE64_ENCODED_KEY_PROVIDED_BY_XENDIT")
let xenIssuing = Xenissuing(xenditKey: xenKey)
let encrypted, sessionKey = xenissuing.encrypt("123".data(using: .utf8))
} catch {
throw Xenissuing.genericError()
}

let xen = Xenissuing(xenditKey: "test".data(using: .utf8)!)
let nonce = try! xen.generateRandom()
let privateKey = try! xen.generateRandom()
let encrypted = try! xen.encrypt(plain: "hTlNMg4CJZVdTIfXBehfxcU0XQ==".data(using: .utf8)!, iv: nonce, sessionKey: privateKey)
let sealed = encrypted.sealed // sealed message
```
18 changes: 9 additions & 9 deletions Sources/Xenissuing/XenCrypt/XenCrypt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ protocol Crypto {

/// Encapsulates encrypted message and key used as encryption key.
public struct EncryptedMessage {
let key: Data
let sealed: Data
internal let key: Data
public let sealed: Data
public init(key: Data, sealed: Data) {
self.key = key
self.sealed = sealed
}
}

// MARK: - XenCrypt
Expand All @@ -53,12 +57,8 @@ public class XenCrypt: Crypto {
- Returns: the random session key.
*/
public func generateRandom() throws -> Data {
do {
let key = SymmetricKey(size: .bits192)
return key.serialize()
} catch {
throw XenError.generateRandomKeyError
}
let key = SymmetricKey(size: .bits192)
return key.serialize()
}

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ public class XenCrypt: Crypto {
if there was any issue during encryption.
- Returns: The encrypted text
*/
public func encrypt(plain: Data, iv: Data, sessionKey: Data) throws -> EncryptedMessage {
public func encrypt(plain: Data, iv _: Data, sessionKey: Data) throws -> EncryptedMessage {
do {
let iv = AES.randomIV(32)
let gcm = GCM(iv: iv, mode: .combined)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Xenissuing/Xenissuing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class Xenissuing: XenCrypt {

- Returns: Main module.
*/
override init(xenditKey: Data) {
override public init(xenditKey: Data) {
super.init(xenditKey: xenditKey)
}
}

0 comments on commit b9788be

Please sign in to comment.