]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSRateLimiter.h
Security-59306.11.20.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 #if OCTAGON
25
26 #import <Foundation/Foundation.h>
27 #import "CKKSOutgoingQueueEntry.h"
28
29 NS_ASSUME_NONNULL_BEGIN
30
31 @interface CKKSRateLimiter : NSObject <NSSecureCoding>
32
33 @property (readonly) NSDictionary* config; // of NSString : NSNumber
34
35 /*!
36 * @brief Find out whether outgoing items are okay to send.
37 * @param entry The outgoing object being judged.
38 * @param time Current time.
39 * @param limitTime In case of badness, this will contain the time at which the object may be sent.
40 * @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.
41 *
42 * 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.
43 * 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
44 * this overloaded state will end.
45 */
46 - (int)judge:(CKKSOutgoingQueueEntry* const)entry
47 at:(NSDate*)time
48 limitTime:(NSDate* _Nonnull __autoreleasing* _Nonnull)limitTime;
49
50 - (instancetype)init;
51 - (instancetype _Nullable)initWithCoder:(NSCoder* _Nullable)coder NS_DESIGNATED_INITIALIZER;
52 - (NSUInteger)stateSize;
53 - (void)reset;
54 - (NSString*)diagnostics;
55
56 + (BOOL)supportsSecureCoding;
57
58 @end
59
60 NS_ASSUME_NONNULL_END
61 #endif