0001    // SSLKey.swift
0002    //
0003    // The MIT License (MIT)
0004    //
0005    // Copyright (c) 2015 Zewo
0006    //
0007    // Permission is hereby granted, free of charge, to any person obtaining a copy
0008    // of this software and associated documentation files (the "Software"), to deal
0009    // in the Software without restriction, including without limitation the rights
0010    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0011    // copies of the Software, and to permit persons to whom the Software is
0012    // furnished to do so, subject to the following conditions:
0013    //
0014    // The above copyright notice and this permission notice shall be included in all
0015    // copies or substantial portions of the Software.
0016    //
0017    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0018    // IMPLIED, INCLUDINbG BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0019    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0020    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0021    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0022    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0023    // SOFTWARE.
0024    
0025    import COpenSSL
0026    
0027    public class Key
Certificate.swift:72
	public init(privateKey: Key, commonName: String, expiresInDays: Int = 365, subjectAltName: String? = nil) throws {
Context.swift:51
	public func usePrivateKey(privateKey: Key) throws {
{ 0028 var key
Certificate.swift:75
		let privateKey = privateKey.key
Context.swift:52
        if SSL_CTX_use_PrivateKey(context, privateKey.key) != 1 {
Key.swift:32
		self.key = key
Key.swift:37
		self.key = PEM_read_bio_PrivateKey(bio.bio, nil, nil, nil)
Key.swift:42
		key = EVP_PKEY_new()
Key.swift:47
		EVP_PKEY_set1_RSA(key, rsa)
: UnsafeMutablePointer<EVP_PKEY> 0029 0030 public init(key: UnsafeMutablePointer<EVP_PKEY>) { 0031 OpenSSL.initialize() 0032 self.key = key 0033 } 0034 0035 public init(filePath: String) throws { 0036 let bio = try IO(filePath: filePath) 0037 self.key = PEM_read_bio_PrivateKey(bio.bio, nil, nil, nil) 0038 } 0039 0040 public init(keyLength: Int32) { 0041 OpenSSL.initialize() 0042 key = EVP_PKEY_new() 0043 let rsa = RSA_new() 0044 let exponent = BN_new() 0045 BN_set_word(exponent, 0x10001) 0046 RSA_generate_key_ex(rsa, keyLength, exponent, nil) 0047 EVP_PKEY_set1_RSA(key, rsa) 0048 } 0049 } 0050