-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
992cac0
commit df99d74
Showing
8 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,54 @@ | ||
// | ||
// Payload.swift | ||
// S3Storage | ||
// | ||
// Created by Anthony Castelli on 4/23/18. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
import Crypto | ||
|
||
public enum Payload { | ||
case bytes(Data) | ||
case none | ||
case unsigned | ||
} | ||
|
||
extension Payload { | ||
internal func hashed() throws -> String { | ||
switch self { | ||
case .bytes(let bytes): return try SHA256.hash(bytes).hexEncodedString() | ||
case .none: return try SHA256.hash("".convertToData()).hexEncodedString() | ||
case .unsigned: return "UNSIGNED-PAYLOAD" | ||
} | ||
} | ||
|
||
internal var bytes: Data { | ||
switch self { | ||
case .bytes(let bytes): return bytes | ||
default: return "".convertToData() | ||
} | ||
} | ||
|
||
internal var isBytes: Bool { | ||
switch self { | ||
case .bytes( _), .none: return true | ||
default: return false | ||
} | ||
} | ||
|
||
internal var size: String { | ||
switch self { | ||
case .bytes, .none: return self.bytes.count.description | ||
case .unsigned: return "UNSIGNED-PAYLOAD" | ||
} | ||
} | ||
|
||
internal var isUnsigned: Bool { | ||
switch self { | ||
case .unsigned: return true | ||
default: return false | ||
} | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
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