Skip to content

Commit 3a399e9

Browse files
committed
Add documentation
1 parent 7fdda8d commit 3a399e9

35 files changed

+3443
-16
lines changed

.jazzy.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Run jazzy from the current directory to generate documentation.
2+
3+
module: PassEncoder
4+
module_version: 1.0.3
5+
author: Ayden Panhuyzen
6+
author_url: https://madebyayden.co
7+
github_url: https://github.com/aydenp/PassEncoder
8+
github_file_prefix: https://github.com/aydenp/PassEncoder/tree/master
9+
min_acl: internal
10+
output: docs
11+
skip_undocumented: true
12+
clean: true
13+
xcodebuild_arguments: [-project, PassEncoder.xcodeproj, -target, PassEncoder]
14+
15+
# Keep this until Cocoadocs is using a Jazzy release with the updated config keys:
16+
module: PassEncoder
17+
author: Ayden Panhuyzen
18+
author_url: https://madebyayden.co

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ Apple Wallet (formerly Passbook) pass encoding and signing in Swift.
1414

1515
## Requirements
1616

17-
- iOS 9.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
17+
- iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
1818
- Or Linux with zlib development package
1919
- Xcode 9.0
2020
- Swift 4.0
21-
22-
(as per [ZIPFoundation](https://github.com/weichsel/ZIPFoundation)'s requirements)
21+
- OpenSSL
2322

2423
## Installation
2524

@@ -31,8 +30,8 @@ Add the following line to your dependencies section of `Package.swift`:
3130

3231
and add "PassEncoder" to your target's dependencies.
3332

34-
> **Heads up!** Because this package requires macOS 10.11+, and as of writing this, SPM does not support setting minimum deployment targets, you will have to manually specify building with that target, or set it in your Xcode project (if applicable).
35-
> swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macosx10.11"
33+
> **Heads up!** Because this package requires macOS 10.12+, and as of writing this, SPM does not support setting minimum deployment targets, you will have to manually specify building with that target, or set it in your Xcode project (if applicable).
34+
> swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macosx10.12"
3635
3736
## Usage
3837

Sources/PassEncoder/PassEncoder.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import CryptoSwift
44

55
/// A class used to encode PassKit passes.
66
/// - NOTE: This class can **only be used once**. After running `encode(signingInfo:, completion:)` once, it will throw a fatal error.
7-
class PassEncoder {
7+
public class PassEncoder {
88
private let directory = FileManager.default.temporaryDirectory.appendingPathComponent("PassEncoder-\(UUID().uuidString)-\(Date().timeIntervalSince1970)")
99
private var isUsed = false, hashes = [String: String](), archive: Archive!
1010

1111
/**
1212
Intiialize the encoder with the provided pass.json data. Will return nil if an error occurs.
1313
- parameter passData: The data to use for pass.json
1414
*/
15-
init?(passData: [String: Any]) {
15+
public init?(passData: [String: Any]) {
1616
// Create our temporary directory
1717
guard (try? FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil)) != nil else { return nil }
1818

@@ -28,11 +28,12 @@ class PassEncoder {
2828
Intiialize the encoder with the provided pass.json URL. Will return nil if an error occurs.
2929
- parameter passDataURL: The URL pass.json is located at.
3030
*/
31-
convenience init?(passDataURL: URL) {
31+
convenience public init?(passDataURL: URL) {
3232
guard let data = try? Data(contentsOf: passDataURL), let json = (try? JSONSerialization.jsonObject(with: data, options: [])) as? [String: Any] else { return nil }
3333
self.init(passData: json)
3434
}
3535

36+
/// Called when deinitializing the encoder. Used to remove our temporary directory.
3637
deinit {
3738
guard FileManager.default.fileExists(atPath: directory.path) else { return }
3839
_ = try? FileManager.default.removeItem(at: directory)
@@ -46,7 +47,7 @@ class PassEncoder {
4647
- parameter customName: A custom name to add the file with.
4748
- returns: Whether or not the operation was successful.
4849
*/
49-
func addFile(from url: URL, customName: String? = nil) -> Bool {
50+
public func addFile(from url: URL, customName: String? = nil) -> Bool {
5051
guard let data = try? Data(contentsOf: url) else { return false }
5152
return addFile(named: customName ?? url.lastPathComponent, from: data)
5253
}
@@ -57,7 +58,7 @@ class PassEncoder {
5758
- parameter data: The data to create the file with.
5859
- returns: Whether or not the operation was successful.
5960
*/
60-
func addFile(named name: String, from data: Data) -> Bool {
61+
public func addFile(named name: String, from data: Data) -> Bool {
6162
guard writeTemporaryFile(to: name, data: data), addFileToArchive(with: name) else { return false }
6263
hashes[name.lowercased()] = data.sha1().toHexString()
6364
return true
@@ -98,7 +99,7 @@ class PassEncoder {
9899
- parameter signingInfo: The certificate and password to sign the pass with. If left out, the pass will not be signed.
99100
- returns: The pass's data, if successful.
100101
*/
101-
func encode(signingInfo: PassSigner.SigningInfo?) -> Data? {
102+
public func encode(signingInfo: PassSigner.SigningInfo?) -> Data? {
102103
guard !isUsed else { fatalError("This PassEncoder has already been used, and may not be used again.") }
103104
isUsed = true
104105

Sources/PassEncoder/PassSigner.swift

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import Foundation
22

3-
struct PassSigner {
3+
/// A singleton class used to sign PassKit passes.
4+
public struct PassSigner {
5+
/// The shared instance of `PassSigner`.
46
static let shared = PassSigner()
5-
var appleWWDRCertURL: URL?, openSSLURL = URL(fileURLWithPath: "/usr/bin/openssl")
67

7-
/// A tuple representing a certificate URL (expected .pem) and password.
8-
typealias SigningInfo = (certificate: URL, password: String)
8+
// MARK: - Options
9+
/// The local URL of the Apple Worldwide Developer Relations Root Certificate Authority (required to sign passes).
10+
public var appleWWDRCertURL: URL?
11+
/// The URL to your OpenSSL binary. Set it if yours is in a different location than /usr/bin/openssl.
12+
public var openSSLURL = URL(fileURLWithPath: "/usr/bin/openssl")
13+
14+
private init() {}
15+
16+
// MARK: - Signing
917

1018
/**
1119
Sign the provided pass manifest data.
20+
- Note: This method will fail and crash your program if you haven't set `appleWWDRCertURL`.
1221
- parameter url: The URL of the pass's manifest.json file.
1322
- parameter signatureURL: The signature URL to write to.
1423
- parameter info: The signing info to sign this pass manifest with.
1524
- returns: Whether or not the operation was successful.
1625
*/
17-
func signPassManifest(at url: URL, toSignatureAt signatureURL: URL, info: SigningInfo) -> Bool {
26+
public func signPassManifest(at url: URL, toSignatureAt signatureURL: URL, info: SigningInfo) -> Bool {
1827
guard let caURL = appleWWDRCertURL else { fatalError("You must specify the location of your Apple WWDR CA certificate (PassSigner.shared.appleWWDRCertURL).") }
1928

2029
let task = Process()
@@ -25,3 +34,9 @@ struct PassSigner {
2534
return task.terminationStatus == 0
2635
}
2736
}
37+
38+
/// MARK: - Types
39+
extension PassSigner {
40+
/// A tuple representing a certificate URL (expected .pem) and password.
41+
public typealias SigningInfo = (certificate: URL, password: String)
42+
}

docs/Classes.html

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Classes Reference</title>
5+
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
6+
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
7+
<meta charset='utf-8'>
8+
<script src="js/jquery.min.js" defer></script>
9+
<script src="js/jazzy.js" defer></script>
10+
11+
</head>
12+
<body>
13+
<a name="//apple_ref/swift/Section/Classes" class="dashAnchor"></a>
14+
<a title="Classes Reference"></a>
15+
<header>
16+
<div class="content-wrapper">
17+
<p><a href="index.html">PassEncoder Docs</a> (100% documented)</p>
18+
<p class="header-right"><a href="https://github.com/aydenp/PassEncoder"><img src="img/gh.png"/>View on GitHub</a></p>
19+
</div>
20+
</header>
21+
<div class="content-wrapper">
22+
<p id="breadcrumbs">
23+
<a href="index.html">PassEncoder Reference</a>
24+
<img id="carat" src="img/carat.png" />
25+
Classes Reference
26+
</p>
27+
</div>
28+
<div class="content-wrapper">
29+
<nav class="sidebar">
30+
<ul class="nav-groups">
31+
<li class="nav-group-name">
32+
<a href="Classes.html">Classes</a>
33+
<ul class="nav-group-tasks">
34+
<li class="nav-group-task">
35+
<a href="Classes/PassEncoder.html">PassEncoder</a>
36+
</li>
37+
</ul>
38+
</li>
39+
<li class="nav-group-name">
40+
<a href="Structs.html">Structures</a>
41+
<ul class="nav-group-tasks">
42+
<li class="nav-group-task">
43+
<a href="Structs/PassSigner.html">PassSigner</a>
44+
</li>
45+
</ul>
46+
</li>
47+
</ul>
48+
</nav>
49+
<article class="main-content">
50+
<section>
51+
<section class="section">
52+
<h1>Classes</h1>
53+
<p>The following classes are available globally.</p>
54+
55+
</section>
56+
<section class="section task-group-section">
57+
<div class="task-group">
58+
<ul>
59+
<li class="item">
60+
<div>
61+
<code>
62+
<a name="/s:11PassEncoderAAC"></a>
63+
<a name="//apple_ref/swift/Class/PassEncoder" class="dashAnchor"></a>
64+
<a class="token" href="#/s:11PassEncoderAAC">PassEncoder</a>
65+
</code>
66+
</div>
67+
<div class="height-container">
68+
<div class="pointer-container"></div>
69+
<section class="section">
70+
<div class="pointer"></div>
71+
<div class="abstract">
72+
<p>A class used to encode PassKit passes.</p>
73+
<div class="aside aside-note">
74+
<p class="aside-title">Note</p>
75+
This class can <strong>only be used once</strong>. After running <code>encode(signingInfo:, completion:)</code> once, it will throw a fatal error.
76+
77+
</div>
78+
79+
<a href="Classes/PassEncoder.html" class="slightly-smaller">See more</a>
80+
</div>
81+
<div class="declaration">
82+
<h4>Declaration</h4>
83+
<div class="language">
84+
<p class="aside-title">Swift</p>
85+
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">PassEncoder</span></code></pre>
86+
87+
</div>
88+
</div>
89+
<div class="slightly-smaller">
90+
<a href="https://github.com/aydenp/PassEncoder/tree/master/Sources/PassEncoder/PassEncoder.swift#L7-L116">Show on GitHub</a>
91+
</div>
92+
</section>
93+
</div>
94+
</li>
95+
</ul>
96+
</div>
97+
</section>
98+
</section>
99+
<section id="footer">
100+
<p>&copy; 2018 <a class="link" href="https://madebyayden.co" target="_blank" rel="external">Ayden Panhuyzen</a>. All rights reserved. (Last updated: 2018-05-06)</p>
101+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
102+
</section>
103+
</article>
104+
</div>
105+
</body>
106+
</div>
107+
</html>

0 commit comments

Comments
 (0)