-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support compression in non Apple platforms
- Loading branch information
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Sources/JWSETKit/Cryptography/Compression/Compressor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Amir Abbas Mousavian on 5/1/24. | ||
// | ||
|
||
import Foundation | ||
#if canImport(SWCompression) | ||
import SWCompression | ||
|
||
extension JSONWebCompressionAlgorithm { | ||
var swCompressor: any CompressionAlgorithm.Type { | ||
get throws { | ||
switch self { | ||
case .deflate: | ||
return Deflate.self | ||
default: | ||
throw JSONWebKeyError.unknownAlgorithm | ||
} | ||
} | ||
} | ||
|
||
var swDecompressor: any DecompressionAlgorithm.Type { | ||
get throws { | ||
switch self { | ||
case .deflate: | ||
return Deflate.self | ||
default: | ||
throw JSONWebKeyError.unknownAlgorithm | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Compressor contain compress and decompress implementation using `Compression` framework. | ||
public struct Compressor<Codec>: JSONWebCompressor, Sendable where Codec: CompressionCodec { | ||
public static func compress<D>(_ data: D) throws -> Data where D: DataProtocol { | ||
try Codec.algorithm.swCompressor.compress(data: Data(data)) | ||
} | ||
|
||
public static func decompress<D>(_ data: D) throws -> Data where D: DataProtocol { | ||
try Codec.algorithm.swDecompressor.decompress(data: Data(data)) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters