1//2// TORAuthKey.h3// Tor4//5// Created by Benjamin Erhart on 29.09.21.6//78#import <Foundation/Foundation.h>910NS_ASSUME_NONNULL_BEGIN1112/**13 The representation of one private or public v3 onion service authentication key.14 */15NS_SWIFT_NAME(TorAuthKey)16@interface TORAuthKey : NSObject1718/**19 The location on disk, where this data was read from/will be written to.20 */21@property (nonatomic, readonly, nonnull) NSURL *file;2223/**24 Flag, if this is a private (\c YES) or a public (\c NO) key.25 */26@property (atomic, readonly) BOOL isPrivate;2728/**29 The full onion service URL.30 */31@property (nonatomic, readonly, nullable) NSURL *onionAddress;3233/**34 The authentication type.3536Currently only the \c descriptor type is supported. This class will set this value hard for you.37 */38@property (nonatomic, readonly, nonnull) NSString *authType;3940/**41 The key type.4243 Currently only \c x25519 is supported. This class will set this value hard for you.44 Make sure, that the key you provide actually is of that type!45 */46@property (nonatomic, readonly, nonnull) NSString *keyType;4748/**49 The actual public OR private key.5051 This class doesn't enforce it, but Tor wants this to be in a BASE32 encoded format.5253 Make sure, it is of the type \c x25519, as this is currently the only supported type by Tor and by this class!54 */55@property (nonatomic, readonly, nonnull) NSString *key;565758/**59 Load from a key file on disk.6061 See https://2019.www.torproject.org/docs/tor-manual.html.en#ClientOnionAuthDir62 and https://2019.www.torproject.org/docs/tor-manual.html.en#_client_authorization63 for the expected format.6465 @param url The URL to the file containing the key. Expected to be in the correct format.66 */67-(instancetype)initFromUrl:(NSURL *)url;6869/**70 Load from a key file on disk.7172 See https://2019.www.torproject.org/docs/tor-manual.html.en#ClientOnionAuthDir73 and https://2019.www.torproject.org/docs/tor-manual.html.en#_client_authorization74 for the expected format.7576 @param path The path to the file containing the key. Expected to be in the correct format.77 */78-(instancetype)initFromFile:(NSString *)path;7980/**81 Create a new private key for a given domain.8283 Normally, the domain will be used as file name, but this method will generate a UUID, if no domain can be found.8485 @param key A \c BASE32 encoded \c x25519 private key.86 @param url A URL containing the v3 onion service domain for which this key is.87 */88-(instancetype)initPrivate:(NSString * _Nonnull)key forDomain:(NSURL * _Nonnull)url;8990/**91 Create a new public key with the given name.9293 The name wil be used as the file name.9495 @param key A \c BASE32 encoded \c x25519 public key.96 @param name A name to identify this key to be used as the file name.97 */98-(instancetype)initPublic:(NSString * _Nonnull)key withName:(NSString *)name;99100101/**102 Set the base directory for the key.103104 This needs to be called \b before \c persist, if you created a fresh key.105106 @param directory The base directory where this key should be persisted.107108 @see -persist109 */110-(void)setDirectory:(NSURL *)directory;111112/**113 Persists this key to the file system.114115 Call \c setDirectory:, if this instance wasn't created by reading a key from a file!116117 @returns \c YES on success, \c NO on failure.118119 @see -setDirectory:120 */121-(BOOL)persist;122123/**124 Keys are considered equal, if their file URLs match.125 */126-(BOOL)isEqualToAuthKey:(TORAuthKey *)authKey;127128129/**130 Checks, if the given file name has the correct extension for either a private or public key.131132 @param url A file URL to a key file.133134 @returns \c YES, if this URL contains a key file extension.135 */136+(BOOL)isAuthFile:(NSURL *)url;137138@end139140NS_ASSUME_NONNULL_END