Skip to content

Commit

Permalink
refactor: ♻️ CryptoFieldをOptionalCryptoFieldに名称変更
Browse files Browse the repository at this point in the history
  • Loading branch information
lemo-nade-room committed Feb 1, 2025
1 parent d9c1273 commit 16601b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Sources/CryptoCodable/CryptoConfigContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation

/// 暗号鍵等の設定を保持するための名前空間
public struct CryptoConfigContainer: Sendable {
/// CryptoFieldのエンコード/デコード時に使用する暗号鍵
/// OptionalCryptoFieldのエンコード/デコード時に使用する暗号鍵
///
/// 暗号化・復号時に事前にセットする必要がある
///
Expand All @@ -25,12 +25,12 @@ public struct CryptoConfigContainer: Sendable {
/// ```
@TaskLocal public static var key: SymmetricKey?

/// CryptoFieldのエンコード/デコード時に使用するJSONEncoder
/// OptionalCryptoFieldのエンコード/デコード時に使用するJSONEncoder
///
/// カスタマイズしたい場合のみ設定が必要
@TaskLocal public static var encoder: JSONEncoder = .init()

/// CryptoFieldのエンコード/デコード時に使用するJSONDecoder
/// OptionalCryptoFieldのエンコード/デコード時に使用するJSONDecoder
///
/// カスタマイズしたい場合のみ設定が必要
@TaskLocal public static var decoder: JSONDecoder = .init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import Foundation
///
/// ## 使用方法
///
/// 1. CryptoFieldプロパティラッパーを使ったCodableな型を定義する
/// 1. OptionalCryptoFieldプロパティラッパーを使ったCodableな型を定義する
///
/// ```swift
/// import CryptoCodable
/// import Foundation
///
/// struct Event: Hashable, Codable, Sendable {
/// var id: UUID
/// @CryptoField var 個人情報: Self.個人情報?
/// @OptionalCryptoField var 個人情報: Self.個人情報?
/// struct 個人情報: Hashable, Codable, Sendable {
/// var 氏名: String
/// var 誕生日: Date
Expand Down Expand Up @@ -58,7 +58,7 @@ import Foundation
/// - throws: `DecryptFailure` 暗号鍵が異なる場合
///
@propertyWrapper
public struct CryptoField<T>: Codable, Sendable, Hashable where T: Sendable & Codable & Hashable {
public struct OptionalCryptoField<T>: Codable, Sendable, Hashable where T: Sendable & Codable & Hashable {
public var wrappedValue: T?

public init(wrappedValue: T?) {
Expand Down Expand Up @@ -92,7 +92,7 @@ public struct CryptoField<T>: Codable, Sendable, Hashable where T: Sendable & Co
get throws {
let json = try CryptoConfigContainer.encoder.encode(wrappedValue)
guard let key = CryptoConfigContainer.key else {
fatalError("暗号鍵が設定されていません。CryptoFieldKey.keyに暗号鍵を設定してください。")
fatalError("暗号鍵が設定されていません。OptionalCryptoFieldKey.keyに暗号鍵を設定してください。")
}
let sealedBox = try AES.GCM.seal(json, using: key)
guard let combined = sealedBox.combined else {
Expand All @@ -108,7 +108,7 @@ public struct CryptoField<T>: Codable, Sendable, Hashable where T: Sendable & Co
/// 基本的に投げられることはないため、エラー処理は不要
public struct EncryptIllegalSizeNounceError: Error, Hashable, Codable, Sendable {}

/// デコード(復号)時にCryptoFieldプロパティが復号に失敗した際に投げられるエラー
/// デコード(復号)時にOptionalCryptoFieldプロパティが復号に失敗した際に投げられるエラー
///
/// 暗号鍵が誤っている場合に投げられる
public struct DecryptFailure: Error, Hashable, Codable, Sendable {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import CryptoCodable
import Foundation
import Testing

@Suite struct CryptoFieldTests {
@Suite struct OptionalCryptoFieldTests {
struct Event: Hashable, Codable, Sendable {
var id: UUID
var 職業: String
@CryptoField var 個人情報: Self.個人情報?
@OptionalCryptoField var 個人情報: Self.個人情報?
struct 個人情報: Hashable, Codable, Sendable {
var 氏名: String
var 誕生日: Date
Expand Down
2 changes: 1 addition & 1 deletion Tests/CryptoCodableTests/SymmetricKeyDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Testing

@Suite struct SymmetricKeyDataTests {
struct Content: Hashable, Codable, Sendable {
@CryptoField var value: String?
@OptionalCryptoField var value: String?
}

@Test func Dataに一度変換したもので復号可能() throws {
Expand Down

0 comments on commit 16601b5

Please sign in to comment.