Skip to content

Make some methods public in Cryptor #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Sources/CryptomatorCryptoLib/Cryptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public enum FileNameEncoding: String {
case base32
}

struct FileHeader {
let nonce: [UInt8]
let contentKey: [UInt8]
public struct FileHeader {
public let nonce: [UInt8]
public let contentKey: [UInt8]
}

public class Cryptor {
Expand All @@ -71,8 +71,8 @@ public class Cryptor {
return contentCryptor.nonceLen + fileHeaderPayloadSize + contentCryptor.tagLen
}

let cleartextChunkSize = 32 * 1024
var ciphertextChunkSize: Int {
public let cleartextChunkSize = 32 * 1024
public var ciphertextChunkSize: Int {
return contentCryptor.nonceLen + cleartextChunkSize + contentCryptor.tagLen
}

Expand Down Expand Up @@ -164,18 +164,18 @@ public class Cryptor {

// MARK: - File Header Encryption and Decryption

func createHeader() throws -> FileHeader {
public func createHeader() throws -> FileHeader {
let nonce = try cryptoSupport.createRandomBytes(size: contentCryptor.nonceLen)
let contentKey = try cryptoSupport.createRandomBytes(size: kCCKeySizeAES256)
return FileHeader(nonce: nonce, contentKey: contentKey)
}

func encryptHeader(_ header: FileHeader) throws -> [UInt8] {
public func encryptHeader(_ header: FileHeader) throws -> [UInt8] {
let cleartext = [UInt8](repeating: 0xFF, count: fileHeaderLegacyPayloadSize) + header.contentKey
return try contentCryptor.encryptHeader(cleartext, key: masterkey.aesMasterKey, nonce: header.nonce)
}

func decryptHeader(_ header: [UInt8]) throws -> FileHeader {
public func decryptHeader(_ header: [UInt8]) throws -> FileHeader {
let nonce = [UInt8](header[0 ..< contentCryptor.nonceLen])
let cleartext = try contentCryptor.decryptHeader(header, key: masterkey.aesMasterKey)
let contentKey = [UInt8](cleartext[fileHeaderLegacyPayloadSize...])
Expand Down Expand Up @@ -311,12 +311,12 @@ public class Cryptor {
}
}

func encryptSingleChunk(_ chunk: [UInt8], chunkNumber: UInt64, headerNonce: [UInt8], fileKey: [UInt8]) throws -> [UInt8] {
public func encryptSingleChunk(_ chunk: [UInt8], chunkNumber: UInt64, headerNonce: [UInt8], fileKey: [UInt8]) throws -> [UInt8] {
let chunkNonce = try cryptoSupport.createRandomBytes(size: contentCryptor.nonceLen)
return try contentCryptor.encryptChunk(chunk, chunkNumber: chunkNumber, chunkNonce: chunkNonce, fileKey: fileKey, headerNonce: headerNonce)
}

func decryptSingleChunk(_ chunk: [UInt8], chunkNumber: UInt64, headerNonce: [UInt8], fileKey: [UInt8]) throws -> [UInt8] {
public func decryptSingleChunk(_ chunk: [UInt8], chunkNumber: UInt64, headerNonce: [UInt8], fileKey: [UInt8]) throws -> [UInt8] {
return try contentCryptor.decryptChunk(chunk, chunkNumber: chunkNumber, fileKey: fileKey, headerNonce: headerNonce)
}

Expand Down