Skip to content

Commit

Permalink
Deallocate
Browse files Browse the repository at this point in the history
  • Loading branch information
irar2 committed Jan 22, 2017
1 parent 05f0d89 commit 0adf0cd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/KituraJWT/RSA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class RSA: EncryptionAlgorithm {
self.keySize = Int32(key.count)
self.keyType = keyType
}

deinit {
key.deinitialize(count: Int(keySize))
key.deallocate(capacity: Int(keySize))
}

/// Signs the given data using the receiver's kay and digest algorithm.
///
Expand All @@ -115,6 +120,7 @@ class RSA: EncryptionAlgorithm {
func sign(_ data: Data) -> Data? {
// Generate hash
let ptr = UnsafeMutablePointer<UInt8>.allocate(capacity: data.count)
defer { ptr.deallocate(capacity: data.count) }
data.copyBytes(to: ptr, count: data.count)
guard let digest = Digest(using: algorithm.digest).update(from: ptr, byteCount: data.count) else {
return nil
Expand Down Expand Up @@ -158,13 +164,15 @@ class RSA: EncryptionAlgorithm {
func verify(signature: Data, for data: Data) -> Bool {
// Generate hash
let ptr = UnsafeMutablePointer<UInt8>.allocate(capacity: data.count)
defer { ptr.deallocate(capacity: data.count) }
data.copyBytes(to: ptr, count: data.count)
guard let digest = Digest(using: algorithm.digest).update(from: ptr, byteCount: data.count) else {
return false
}
var digestBytes = digest.final()

let signPtr = UnsafeMutablePointer<UInt8>.allocate(capacity: signature.count)
defer { signPtr.deallocate(capacity: data.count) }
signature.copyBytes(to: signPtr, count: signature.count)

let keybuf = BIO_new_mem_buf(key, keySize)
Expand Down

0 comments on commit 0adf0cd

Please sign in to comment.