@@ -166,15 +166,16 @@ - (instancetype)initWithIdentifier:(NSString *)identifier
166166 state : (SNTRuleState)state
167167 type : (SNTRuleType)type
168168 customMsg : (NSString *)customMsg
169- customURL : (NSString *)customURL {
169+ customURL : (NSString *)customURL
170+ celExpr : (NSString *)celExpr {
170171 self = [self initWithIdentifier: identifier
171172 state: state
172173 type: type
173174 customMsg: customMsg
174175 customURL: customURL
175176 timestamp: 0
176177 comment: nil
177- celExpr: nil
178+ celExpr: celExpr
178179 error: nil ];
179180 // Initialize timestamp to current time if rule is transitive.
180181 if (self && state == SNTRuleStateAllowTransitive) {
@@ -186,7 +187,15 @@ - (instancetype)initWithIdentifier:(NSString *)identifier
186187- (instancetype )initWithIdentifier : (NSString *)identifier
187188 state : (SNTRuleState)state
188189 type : (SNTRuleType)type {
189- return [self initWithIdentifier: identifier state: state type: type customMsg: nil customURL: nil ];
190+ return [self initWithIdentifier: identifier
191+ state: state
192+ type: type
193+ customMsg: nil
194+ customURL: nil
195+ timestamp: 0
196+ comment: nil
197+ celExpr: nil
198+ error: nil ];
190199}
191200
192201// lowercase policy keys and upper case the policy decision.
@@ -254,6 +263,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)rawDict error:(NSError **)err
254263 state = SNTRuleStateSilentBlock;
255264 } else if ([policyString isEqual: kRulePolicyRemove ]) {
256265 state = SNTRuleStateRemove;
266+ } else if ([policyString isEqual: kRulePolicyCEL ]) {
267+ state = SNTRuleStateCEL;
257268 } else {
258269 [SNTError populateError: error
259270 withCode: SNTErrorCodeRuleInvalidPolicy
@@ -301,14 +312,19 @@ - (instancetype)initWithDictionary:(NSDictionary *)rawDict error:(NSError **)err
301312 comment = nil ;
302313 }
303314
315+ NSString *celExpr = dict[kRuleCELExpr ];
316+ if (![celExpr isKindOfClass: [NSString class ]] || celExpr.length == 0 ) {
317+ celExpr = nil ;
318+ }
319+
304320 return [self initWithIdentifier: identifier
305321 state: state
306322 type: type
307323 customMsg: customMsg
308324 customURL: customURL
309325 timestamp: 0
310326 comment: comment
311- celExpr: nil
327+ celExpr: celExpr
312328 error: error];
313329}
314330
@@ -354,6 +370,7 @@ - (NSString *)ruleStateToPolicyString:(SNTRuleState)state {
354370 case SNTRuleStateAllowTransitive: return @" AllowTransitive" ;
355371 case SNTRuleStateAllowLocalBinary: return kRulePolicyAllowlistLocalBinary ;
356372 case SNTRuleStateAllowLocalSigningID: return kRulePolicyAllowlistLocalSigningID ;
373+ case SNTRuleStateCEL: return kRulePolicyCEL ;
357374 // This should never be hit. But is here for completion.
358375 default : return @" Unknown" ;
359376 }
@@ -381,6 +398,7 @@ - (NSDictionary *)dictionaryRepresentation {
381398 kRuleCustomMsg : self.customMsg ?: @" " ,
382399 kRuleCustomURL : self.customURL ?: @" " ,
383400 kRuleComment : self.comment ?: @" " ,
401+ kRuleCELExpr : self.celExpr ?: @" " ,
384402 };
385403}
386404
@@ -399,6 +417,7 @@ - (NSUInteger)hash {
399417 result = prime * result + self.state ;
400418 result = prime * result + self.type ;
401419 result = prime * result + [self .celExpr hash ];
420+ result = prime * result + [self .celExpr hash ];
402421 return result;
403422}
404423
0 commit comments