]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSRateLimiter.h
Security-58286.1.32.tar.gz
[apple/security.git] / keychain / ckks / CKKSRateLimiter.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef RateLimiter_h
25 #define RateLimiter_h
26
27 #if OCTAGON
28
29 #import <Foundation/Foundation.h>
30 #import "CKKSOutgoingQueueEntry.h"
31
32 @interface CKKSRateLimiter : NSObject <NSSecureCoding>
33
34 @property (readonly, nonnull) NSDictionary * config; // of NSString : NSNumber
35
36 /*!
37 * @brief Find out whether outgoing items are okay to send.
38 * @param entry The outgoing object being judged.
39 * @param time Current time.
40 * @param limitTime In case of badness, this will contain the time at which the object may be sent.
41 * @return Badness score from 0 (fine to send immediately) to 5 (overload, keep back), or -1 in case caller does not provide an NSDate object.
42 *
43 * judge:at: will set the limitTime object to nil in case of 0 badness. For badnesses 1-4 the time object will indicate when it is okay to send the entry.
44 * At badness 5 judge:at: has determined there is too much activity so the caller should hold off altogether. The limitTime object will indicate when
45 * this overloaded state will end.
46 */
47 - (int)judge:(CKKSOutgoingQueueEntry * _Nonnull const)entry
48 at:(NSDate * _Nonnull)time
49 limitTime:(NSDate * _Nonnull __autoreleasing * _Nonnull) limitTime;
50
51 - (instancetype _Nullable)init;
52 - (instancetype _Nullable)initWithCoder:(NSCoder * _Nullable)coder NS_DESIGNATED_INITIALIZER;
53 - (NSUInteger)stateSize;
54 - (void)reset;
55 - (NSString * _Nonnull)diagnostics;
56
57 + (BOOL)supportsSecureCoding;
58
59 @end
60
61 #endif
62 #endif