]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/RequirementParser.cpp
Security-58286.200.222.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / lib / RequirementParser.cpp
1 /* $ANTLR 2.7.7 (20121221): "requirements.grammar" -> "RequirementParser.cpp"$ */
2 #include "RequirementParser.hpp"
3 #include <antlr/NoViableAltException.hpp>
4 #include <antlr/SemanticException.hpp>
5 #include <antlr/ASTFactory.hpp>
6
7 #include "requirement.h"
8 #include "reqmaker.h"
9 #include "csutilities.h"
10 #include <security_utilities/cfutilities.h>
11 #include <security_utilities/hashing.h>
12 #include <security_cdsa_utilities/cssmdata.h> // OID coding
13 using namespace CodeSigning;
14 typedef Requirement::Maker Maker;
15
16 ANTLR_BEGIN_NAMESPACE(Security_CodeSigning)
17
18 //
19 // Collect error messages.
20 // Note that the immediate caller takes the absence of collected error messages
21 // to indicate compilation success.
22 //
23 void RequirementParser::reportError(const antlr::RecognitionException &ex)
24 {
25 errors += ex.toString() + "\n";
26 }
27
28 void RequirementParser::reportError(const std::string &s)
29 {
30 errors += s + "\n";
31 }
32
33
34 //
35 // Parser helper functions
36 //
37 string RequirementParser::hexString(const string &s)
38 {
39 if (s.size() % 2)
40 throw antlr::SemanticException("odd number of digits");
41 const char *p = s.data();
42 string result;
43 for (unsigned n = 0; n < s.length(); n += 2) {
44 char c;
45 sscanf(p+n, "%2hhx", &c);
46 result.push_back(c);
47 }
48 return result;
49 }
50
51 void RequirementParser::hashString(const string &s, SHA1::Digest hash)
52 {
53 if (s.size() != 2 * SHA1::digestLength)
54 throw antlr::SemanticException("invalid hash length");
55 memcpy(hash, hexString(s).data(), SHA1::digestLength);
56 }
57
58 static const char *matchPrefix(const string &key, const char *prefix)
59 {
60 size_t pLength = strlen(prefix);
61 if (!key.compare(0, pLength, prefix, 0, pLength))
62 return key.c_str() + pLength;
63 else
64 return NULL;
65 }
66
67 void RequirementParser::certMatchOperation(Maker &maker, int32_t slot, string key)
68 {
69 if (matchPrefix(key, "subject.")) {
70 maker.put(opCertField);
71 maker.put(slot);
72 maker.put(key);
73 } else if (const char *oids = matchPrefix(key, "field.")) {
74 maker.put(opCertGeneric);
75 maker.put(slot);
76 CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
77 maker.putData(oid.data(), oid.length());
78 } else if (const char *oids = matchPrefix(key, "extension.")) {
79 maker.put(opCertGeneric);
80 maker.put(slot);
81 CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
82 maker.putData(oid.data(), oid.length());
83 } else if (const char *oids = matchPrefix(key, "policy.")) {
84 maker.put(opCertPolicy);
85 maker.put(slot);
86 CssmAutoData oid(Allocator::standard()); oid.fromOid(oids);
87 maker.putData(oid.data(), oid.length());
88 } else {
89 throw antlr::SemanticException(key + ": unrecognized certificate field");
90 }
91 }
92
93 RequirementParser::RequirementParser(antlr::TokenBuffer& tokenBuf, int k)
94 : antlr::LLkParser(tokenBuf,k)
95 {
96 }
97
98 RequirementParser::RequirementParser(antlr::TokenBuffer& tokenBuf)
99 : antlr::LLkParser(tokenBuf,2)
100 {
101 }
102
103 RequirementParser::RequirementParser(antlr::TokenStream& lexer, int k)
104 : antlr::LLkParser(lexer,k)
105 {
106 }
107
108 RequirementParser::RequirementParser(antlr::TokenStream& lexer)
109 : antlr::LLkParser(lexer,2)
110 {
111 }
112
113 RequirementParser::RequirementParser(const antlr::ParserSharedInputState& state)
114 : antlr::LLkParser(state,2)
115 {
116 }
117
118 BlobCore * RequirementParser::autosense() {
119 BlobCore *result = NULL;
120
121 try { // for error handling
122 switch ( LA(1)) {
123 case LPAREN:
124 case NOT:
125 case LITERAL_always:
126 case LITERAL_true:
127 case LITERAL_never:
128 case LITERAL_false:
129 case LITERAL_identifier:
130 case LITERAL_cdhash:
131 case LITERAL_platform:
132 case LITERAL_notarized:
133 case LITERAL_anchor:
134 case LITERAL_certificate:
135 case LITERAL_cert:
136 case LITERAL_info:
137 case LITERAL_entitlement:
138 {
139 result=requirement();
140 break;
141 }
142 case LITERAL_guest:
143 case LITERAL_host:
144 case LITERAL_designated:
145 case LITERAL_library:
146 case LITERAL_plugin:
147 case INTEGER:
148 {
149 result=requirementSet();
150 break;
151 }
152 default:
153 {
154 throw antlr::NoViableAltException(LT(1), getFilename());
155 }
156 }
157 }
158 catch (antlr::RecognitionException& ex) {
159 reportError(ex);
160 recover(ex,_tokenSet_0);
161 }
162 return result;
163 }
164
165 Requirement * RequirementParser::requirement() {
166 Requirement *result = NULL;
167
168 try { // for error handling
169 result=requirementElement();
170 match(antlr::Token::EOF_TYPE);
171 }
172 catch (antlr::RecognitionException& ex) {
173 reportError(ex);
174 recover(ex,_tokenSet_0);
175 }
176 return result;
177 }
178
179 Requirements * RequirementParser::requirementSet() {
180 Requirements *result = NULL;
181 Requirements::Maker maker;
182
183 try { // for error handling
184 { // ( ... )+
185 int _cnt4=0;
186 for (;;) {
187 if ((_tokenSet_1.member(LA(1)))) {
188 uint32_t t; Requirement *req;
189 t=requirementType();
190 match(ARROW);
191 req=requirementElement();
192 maker.add(t, req);
193 }
194 else {
195 if ( _cnt4>=1 ) { goto _loop4; } else {throw antlr::NoViableAltException(LT(1), getFilename());}
196 }
197
198 _cnt4++;
199 }
200 _loop4:;
201 } // ( ... )+
202 result = errors.empty() ? maker() : NULL;
203 match(antlr::Token::EOF_TYPE);
204 }
205 catch (antlr::RecognitionException& ex) {
206 reportError(ex);
207 recover(ex,_tokenSet_0);
208 }
209 return result;
210 }
211
212 uint32_t RequirementParser::requirementType() {
213 uint32_t type = kSecInvalidRequirementType;
214
215 try { // for error handling
216 switch ( LA(1)) {
217 case LITERAL_guest:
218 {
219 match(LITERAL_guest);
220 type = kSecGuestRequirementType;
221 break;
222 }
223 case LITERAL_host:
224 {
225 match(LITERAL_host);
226 type = kSecHostRequirementType;
227 break;
228 }
229 case LITERAL_designated:
230 {
231 match(LITERAL_designated);
232 type = kSecDesignatedRequirementType;
233 break;
234 }
235 case LITERAL_library:
236 {
237 match(LITERAL_library);
238 type = kSecLibraryRequirementType;
239 break;
240 }
241 case LITERAL_plugin:
242 {
243 match(LITERAL_plugin);
244 type = kSecPluginRequirementType;
245 break;
246 }
247 case INTEGER:
248 {
249 type=integer();
250 break;
251 }
252 default:
253 {
254 throw antlr::NoViableAltException(LT(1), getFilename());
255 }
256 }
257 }
258 catch (antlr::RecognitionException& ex) {
259 reportError(ex);
260 recover(ex,_tokenSet_2);
261 }
262 return type;
263 }
264
265 Requirement * RequirementParser::requirementElement() {
266 Requirement *result = NULL;
267 Requirement::Maker maker;
268
269 try { // for error handling
270 expr(maker);
271 result = maker();
272 { // ( ... )*
273 for (;;) {
274 if ((LA(1) == SEMI)) {
275 fluff();
276 }
277 else {
278 goto _loop9;
279 }
280
281 }
282 _loop9:;
283 } // ( ... )*
284 }
285 catch (antlr::RecognitionException& ex) {
286 reportError(ex);
287 recover(ex,_tokenSet_3);
288 }
289 return result;
290 }
291
292 int32_t RequirementParser::integer() {
293 int32_t result;
294 antlr::RefToken s = antlr::nullToken;
295
296 try { // for error handling
297 s = LT(1);
298 match(INTEGER);
299 result = int32_t(atol(s->getText().c_str()));
300 }
301 catch (antlr::RecognitionException& ex) {
302 reportError(ex);
303 recover(ex,_tokenSet_4);
304 }
305 return result;
306 }
307
308 void RequirementParser::expr(
309 Maker &maker
310 ) {
311 Maker::Label label(maker);
312
313 try { // for error handling
314 term(maker);
315 { // ( ... )*
316 for (;;) {
317 if ((LA(1) == LITERAL_or)) {
318 match(LITERAL_or);
319 maker.insert<ExprOp>(label) = opOr;
320 term(maker);
321 }
322 else {
323 goto _loop12;
324 }
325
326 }
327 _loop12:;
328 } // ( ... )*
329 }
330 catch (antlr::RecognitionException& ex) {
331 reportError(ex);
332 recover(ex,_tokenSet_5);
333 }
334 }
335
336 void RequirementParser::fluff() {
337
338 try { // for error handling
339 match(SEMI);
340 }
341 catch (antlr::RecognitionException& ex) {
342 reportError(ex);
343 recover(ex,_tokenSet_6);
344 }
345 }
346
347 void RequirementParser::term(
348 Maker &maker
349 ) {
350 Maker::Label label(maker);
351
352 try { // for error handling
353 primary(maker);
354 { // ( ... )*
355 for (;;) {
356 if ((LA(1) == LITERAL_and)) {
357 match(LITERAL_and);
358 maker.insert<ExprOp>(label) = opAnd;
359 primary(maker);
360 }
361 else {
362 goto _loop15;
363 }
364
365 }
366 _loop15:;
367 } // ( ... )*
368 }
369 catch (antlr::RecognitionException& ex) {
370 reportError(ex);
371 recover(ex,_tokenSet_7);
372 }
373 }
374
375 void RequirementParser::primary(
376 Maker &maker
377 ) {
378
379 try { // for error handling
380 switch ( LA(1)) {
381 case NOT:
382 {
383 match(NOT);
384 maker.put(opNot);
385 primary(maker);
386 break;
387 }
388 case LITERAL_always:
389 case LITERAL_true:
390 {
391 {
392 switch ( LA(1)) {
393 case LITERAL_always:
394 {
395 match(LITERAL_always);
396 break;
397 }
398 case LITERAL_true:
399 {
400 match(LITERAL_true);
401 break;
402 }
403 default:
404 {
405 throw antlr::NoViableAltException(LT(1), getFilename());
406 }
407 }
408 }
409 maker.put(opTrue);
410 break;
411 }
412 case LITERAL_never:
413 case LITERAL_false:
414 {
415 {
416 switch ( LA(1)) {
417 case LITERAL_never:
418 {
419 match(LITERAL_never);
420 break;
421 }
422 case LITERAL_false:
423 {
424 match(LITERAL_false);
425 break;
426 }
427 default:
428 {
429 throw antlr::NoViableAltException(LT(1), getFilename());
430 }
431 }
432 }
433 maker.put(opFalse);
434 break;
435 }
436 case LITERAL_anchor:
437 case LITERAL_certificate:
438 case LITERAL_cert:
439 {
440 certspec(maker);
441 break;
442 }
443 case LITERAL_info:
444 {
445 infospec(maker);
446 break;
447 }
448 case LITERAL_entitlement:
449 {
450 entitlementspec(maker);
451 break;
452 }
453 case LITERAL_identifier:
454 {
455 match(LITERAL_identifier);
456 string code;
457 eql();
458 code=identifierString();
459 maker.ident(code);
460 break;
461 }
462 case LITERAL_cdhash:
463 {
464 match(LITERAL_cdhash);
465 SHA1::Digest digest;
466 eql();
467 hash(digest);
468 maker.cdhash(digest);
469 break;
470 }
471 case LITERAL_platform:
472 {
473 match(LITERAL_platform);
474 int32_t ident;
475 eql();
476 ident=integer();
477 maker.platform(ident);
478 break;
479 }
480 case LITERAL_notarized:
481 {
482 match(LITERAL_notarized);
483 maker.put(opNotarized);
484 break;
485 }
486 default:
487 if ((LA(1) == LPAREN) && (_tokenSet_8.member(LA(2)))) {
488 match(LPAREN);
489 expr(maker);
490 match(RPAREN);
491 }
492 else if ((LA(1) == LPAREN) && (LA(2) == DOTKEY || LA(2) == STRING)) {
493 match(LPAREN);
494 string name;
495 name=identifierString();
496 match(RPAREN);
497 maker.put(opNamedCode); maker.put(name);
498 }
499 else {
500 throw antlr::NoViableAltException(LT(1), getFilename());
501 }
502 }
503 }
504 catch (antlr::RecognitionException& ex) {
505 reportError(ex);
506 recover(ex,_tokenSet_9);
507 }
508 }
509
510 void RequirementParser::certspec(
511 Maker &maker
512 ) {
513
514 try { // for error handling
515 if ((LA(1) == LITERAL_anchor) && (LA(2) == LITERAL_apple)) {
516 match(LITERAL_anchor);
517 match(LITERAL_apple);
518 appleanchor(maker);
519 }
520 else if ((LA(1) == LITERAL_anchor) && (LA(2) == LITERAL_generic)) {
521 match(LITERAL_anchor);
522 match(LITERAL_generic);
523 match(LITERAL_apple);
524 maker.put(opAppleGenericAnchor);
525 }
526 else if ((LA(1) == LITERAL_anchor || LA(1) == LITERAL_certificate || LA(1) == LITERAL_cert) && (LA(2) == LITERAL_trusted)) {
527 {
528 switch ( LA(1)) {
529 case LITERAL_certificate:
530 {
531 match(LITERAL_certificate);
532 break;
533 }
534 case LITERAL_cert:
535 {
536 match(LITERAL_cert);
537 break;
538 }
539 case LITERAL_anchor:
540 {
541 match(LITERAL_anchor);
542 break;
543 }
544 default:
545 {
546 throw antlr::NoViableAltException(LT(1), getFilename());
547 }
548 }
549 }
550 match(LITERAL_trusted);
551 maker.trustedAnchor();
552 }
553 else if ((LA(1) == LITERAL_certificate || LA(1) == LITERAL_cert) && (_tokenSet_10.member(LA(2)))) {
554 {
555 switch ( LA(1)) {
556 case LITERAL_certificate:
557 {
558 match(LITERAL_certificate);
559 break;
560 }
561 case LITERAL_cert:
562 {
563 match(LITERAL_cert);
564 break;
565 }
566 default:
567 {
568 throw antlr::NoViableAltException(LT(1), getFilename());
569 }
570 }
571 }
572 int32_t slot;
573 slot=certSlot();
574 {
575 switch ( LA(1)) {
576 case EQL:
577 case EQQL:
578 case LBRACK:
579 case HASHCONSTANT:
580 case DOTKEY:
581 case STRING:
582 case PATHNAME:
583 {
584 certslotspec(maker, slot);
585 break;
586 }
587 case LITERAL_trusted:
588 {
589 match(LITERAL_trusted);
590 maker.trustedAnchor(slot);
591 break;
592 }
593 default:
594 {
595 throw antlr::NoViableAltException(LT(1), getFilename());
596 }
597 }
598 }
599 }
600 else if ((LA(1) == LITERAL_anchor) && (_tokenSet_11.member(LA(2)))) {
601 match(LITERAL_anchor);
602 certslotspec(maker, Requirement::anchorCert);
603 }
604 else {
605 throw antlr::NoViableAltException(LT(1), getFilename());
606 }
607
608 }
609 catch (antlr::RecognitionException& ex) {
610 reportError(ex);
611 recover(ex,_tokenSet_9);
612 }
613 }
614
615 void RequirementParser::infospec(
616 Maker &maker
617 ) {
618 string key;
619
620 try { // for error handling
621 match(LITERAL_info);
622 key=bracketKey();
623 maker.put(opInfoKeyField); maker.put(key);
624 match_suffix(maker);
625 }
626 catch (antlr::RecognitionException& ex) {
627 reportError(ex);
628 recover(ex,_tokenSet_9);
629 }
630 }
631
632 void RequirementParser::entitlementspec(
633 Maker &maker
634 ) {
635 string key;
636
637 try { // for error handling
638 match(LITERAL_entitlement);
639 key=bracketKey();
640 maker.put(opEntitlementField); maker.put(key);
641 match_suffix(maker);
642 }
643 catch (antlr::RecognitionException& ex) {
644 reportError(ex);
645 recover(ex,_tokenSet_9);
646 }
647 }
648
649 void RequirementParser::eql() {
650
651 try { // for error handling
652 switch ( LA(1)) {
653 case EQL:
654 {
655 match(EQL);
656 break;
657 }
658 case EQQL:
659 {
660 match(EQQL);
661 break;
662 }
663 case HASHCONSTANT:
664 case DOTKEY:
665 case STRING:
666 case PATHNAME:
667 case INTEGER:
668 {
669 empty();
670 break;
671 }
672 default:
673 {
674 throw antlr::NoViableAltException(LT(1), getFilename());
675 }
676 }
677 }
678 catch (antlr::RecognitionException& ex) {
679 reportError(ex);
680 recover(ex,_tokenSet_12);
681 }
682 }
683
684 string RequirementParser::identifierString() {
685 string result;
686 antlr::RefToken dk = antlr::nullToken;
687 antlr::RefToken s = antlr::nullToken;
688
689 try { // for error handling
690 switch ( LA(1)) {
691 case DOTKEY:
692 {
693 dk = LT(1);
694 match(DOTKEY);
695 result = dk->getText();
696 break;
697 }
698 case STRING:
699 {
700 s = LT(1);
701 match(STRING);
702 result = s->getText();
703 break;
704 }
705 default:
706 {
707 throw antlr::NoViableAltException(LT(1), getFilename());
708 }
709 }
710 }
711 catch (antlr::RecognitionException& ex) {
712 reportError(ex);
713 recover(ex,_tokenSet_9);
714 }
715 return result;
716 }
717
718 void RequirementParser::hash(
719 SHA1::Digest digest
720 ) {
721 antlr::RefToken hash = antlr::nullToken;
722
723 try { // for error handling
724 hash = LT(1);
725 match(HASHCONSTANT);
726 hashString(hash->getText(), digest);
727 }
728 catch (antlr::RecognitionException& ex) {
729 reportError(ex);
730 recover(ex,_tokenSet_9);
731 }
732 }
733
734 void RequirementParser::appleanchor(
735 Maker &maker
736 ) {
737
738 try { // for error handling
739 switch ( LA(1)) {
740 case antlr::Token::EOF_TYPE:
741 case LITERAL_guest:
742 case LITERAL_host:
743 case LITERAL_designated:
744 case LITERAL_library:
745 case LITERAL_plugin:
746 case LITERAL_or:
747 case LITERAL_and:
748 case RPAREN:
749 case INTEGER:
750 case SEMI:
751 {
752 empty();
753 maker.put(opAppleAnchor);
754 break;
755 }
756 case LITERAL_generic:
757 {
758 match(LITERAL_generic);
759 maker.put(opAppleGenericAnchor);
760 break;
761 }
762 case DOTKEY:
763 case STRING:
764 {
765 string name;
766 name=identifierString();
767 maker.put(opNamedAnchor); maker.put(name);
768 break;
769 }
770 default:
771 {
772 throw antlr::NoViableAltException(LT(1), getFilename());
773 }
774 }
775 }
776 catch (antlr::RecognitionException& ex) {
777 reportError(ex);
778 recover(ex,_tokenSet_9);
779 }
780 }
781
782 int32_t RequirementParser::certSlot() {
783 int32_t slot = 0;
784
785 try { // for error handling
786 switch ( LA(1)) {
787 case INTEGER:
788 {
789 slot=integer();
790 break;
791 }
792 case NEG:
793 {
794 match(NEG);
795 slot=integer();
796 slot = -slot;
797 break;
798 }
799 case LITERAL_leaf:
800 {
801 match(LITERAL_leaf);
802 slot = Requirement::leafCert;
803 break;
804 }
805 case LITERAL_root:
806 {
807 match(LITERAL_root);
808 slot = Requirement::anchorCert;
809 break;
810 }
811 default:
812 {
813 throw antlr::NoViableAltException(LT(1), getFilename());
814 }
815 }
816 }
817 catch (antlr::RecognitionException& ex) {
818 reportError(ex);
819 recover(ex,_tokenSet_13);
820 }
821 return slot;
822 }
823
824 void RequirementParser::certslotspec(
825 Maker &maker, int32_t slot
826 ) {
827 string key;
828
829 try { // for error handling
830 switch ( LA(1)) {
831 case EQL:
832 case EQQL:
833 case HASHCONSTANT:
834 case DOTKEY:
835 case STRING:
836 case PATHNAME:
837 {
838 eql();
839 SHA1::Digest digest;
840 certificateDigest(digest);
841 maker.anchor(slot, digest);
842 break;
843 }
844 case LBRACK:
845 {
846 key=bracketKey();
847 certMatchOperation(maker, slot, key);
848 match_suffix(maker);
849 break;
850 }
851 default:
852 {
853 throw antlr::NoViableAltException(LT(1), getFilename());
854 }
855 }
856 }
857 catch (antlr::RecognitionException& ex) {
858 reportError(ex);
859 recover(ex,_tokenSet_9);
860 }
861 }
862
863 void RequirementParser::empty() {
864
865 try { // for error handling
866 }
867 catch (antlr::RecognitionException& ex) {
868 reportError(ex);
869 recover(ex,_tokenSet_14);
870 }
871 }
872
873 void RequirementParser::certificateDigest(
874 SHA1::Digest digest
875 ) {
876
877 try { // for error handling
878 switch ( LA(1)) {
879 case HASHCONSTANT:
880 {
881 hash(digest);
882 break;
883 }
884 case DOTKEY:
885 case STRING:
886 case PATHNAME:
887 {
888 string path;
889 path=pathstring();
890 if (CFRef<CFDataRef> certData = cfLoadFile(path))
891 hashOfCertificate(CFDataGetBytePtr(certData), CFDataGetLength(certData), digest);
892 else
893 throw antlr::SemanticException(path + ": not found");
894
895 break;
896 }
897 default:
898 {
899 throw antlr::NoViableAltException(LT(1), getFilename());
900 }
901 }
902 }
903 catch (antlr::RecognitionException& ex) {
904 reportError(ex);
905 recover(ex,_tokenSet_9);
906 }
907 }
908
909 string RequirementParser::bracketKey() {
910 string key;
911
912 try { // for error handling
913 match(LBRACK);
914 key=stringvalue();
915 match(RBRACK);
916 }
917 catch (antlr::RecognitionException& ex) {
918 reportError(ex);
919 recover(ex,_tokenSet_15);
920 }
921 return key;
922 }
923
924 void RequirementParser::match_suffix(
925 Maker &maker
926 ) {
927
928 try { // for error handling
929 switch ( LA(1)) {
930 case antlr::Token::EOF_TYPE:
931 case LITERAL_guest:
932 case LITERAL_host:
933 case LITERAL_designated:
934 case LITERAL_library:
935 case LITERAL_plugin:
936 case LITERAL_or:
937 case LITERAL_and:
938 case RPAREN:
939 case LITERAL_exists:
940 case INTEGER:
941 case SEMI:
942 {
943 empty();
944 {
945 switch ( LA(1)) {
946 case LITERAL_exists:
947 {
948 match(LITERAL_exists);
949 break;
950 }
951 case antlr::Token::EOF_TYPE:
952 case LITERAL_guest:
953 case LITERAL_host:
954 case LITERAL_designated:
955 case LITERAL_library:
956 case LITERAL_plugin:
957 case LITERAL_or:
958 case LITERAL_and:
959 case RPAREN:
960 case INTEGER:
961 case SEMI:
962 {
963 break;
964 }
965 default:
966 {
967 throw antlr::NoViableAltException(LT(1), getFilename());
968 }
969 }
970 }
971 maker.put(matchExists);
972 break;
973 }
974 case EQL:
975 case EQQL:
976 {
977 {
978 switch ( LA(1)) {
979 case EQL:
980 {
981 match(EQL);
982 break;
983 }
984 case EQQL:
985 {
986 match(EQQL);
987 break;
988 }
989 default:
990 {
991 throw antlr::NoViableAltException(LT(1), getFilename());
992 }
993 }
994 }
995 MatchOperation mop = matchEqual; string value;
996 {
997 switch ( LA(1)) {
998 case STAR:
999 {
1000 match(STAR);
1001 mop = matchEndsWith;
1002 break;
1003 }
1004 case HEXCONSTANT:
1005 case DOTKEY:
1006 case STRING:
1007 {
1008 break;
1009 }
1010 default:
1011 {
1012 throw antlr::NoViableAltException(LT(1), getFilename());
1013 }
1014 }
1015 }
1016 value=datavalue();
1017 {
1018 switch ( LA(1)) {
1019 case STAR:
1020 {
1021 match(STAR);
1022 mop = (mop == matchEndsWith) ? matchContains : matchBeginsWith;
1023 break;
1024 }
1025 case antlr::Token::EOF_TYPE:
1026 case LITERAL_guest:
1027 case LITERAL_host:
1028 case LITERAL_designated:
1029 case LITERAL_library:
1030 case LITERAL_plugin:
1031 case LITERAL_or:
1032 case LITERAL_and:
1033 case RPAREN:
1034 case INTEGER:
1035 case SEMI:
1036 {
1037 break;
1038 }
1039 default:
1040 {
1041 throw antlr::NoViableAltException(LT(1), getFilename());
1042 }
1043 }
1044 }
1045 maker.put(mop); maker.put(value);
1046 break;
1047 }
1048 case SUBS:
1049 {
1050 match(SUBS);
1051 string value;
1052 value=datavalue();
1053 maker.put(matchContains); maker.put(value);
1054 break;
1055 }
1056 case LESS:
1057 {
1058 match(LESS);
1059 string value;
1060 value=datavalue();
1061 maker.put(matchLessThan); maker.put(value);
1062 break;
1063 }
1064 case GT:
1065 {
1066 match(GT);
1067 string value;
1068 value=datavalue();
1069 maker.put(matchGreaterThan); maker.put(value);
1070 break;
1071 }
1072 case LE:
1073 {
1074 match(LE);
1075 string value;
1076 value=datavalue();
1077 maker.put(matchLessEqual); maker.put(value);
1078 break;
1079 }
1080 case GE:
1081 {
1082 match(GE);
1083 string value;
1084 value=datavalue();
1085 maker.put(matchGreaterEqual); maker.put(value);
1086 break;
1087 }
1088 default:
1089 {
1090 throw antlr::NoViableAltException(LT(1), getFilename());
1091 }
1092 }
1093 }
1094 catch (antlr::RecognitionException& ex) {
1095 reportError(ex);
1096 recover(ex,_tokenSet_9);
1097 }
1098 }
1099
1100 string RequirementParser::datavalue() {
1101 string result;
1102 antlr::RefToken hex = antlr::nullToken;
1103
1104 try { // for error handling
1105 switch ( LA(1)) {
1106 case DOTKEY:
1107 case STRING:
1108 {
1109 result=stringvalue();
1110 break;
1111 }
1112 case HEXCONSTANT:
1113 {
1114 hex = LT(1);
1115 match(HEXCONSTANT);
1116 result = hexString(hex->getText());
1117 break;
1118 }
1119 default:
1120 {
1121 throw antlr::NoViableAltException(LT(1), getFilename());
1122 }
1123 }
1124 }
1125 catch (antlr::RecognitionException& ex) {
1126 reportError(ex);
1127 recover(ex,_tokenSet_16);
1128 }
1129 return result;
1130 }
1131
1132 string RequirementParser::stringvalue() {
1133 string result;
1134 antlr::RefToken dk = antlr::nullToken;
1135 antlr::RefToken s = antlr::nullToken;
1136
1137 try { // for error handling
1138 switch ( LA(1)) {
1139 case DOTKEY:
1140 {
1141 dk = LT(1);
1142 match(DOTKEY);
1143 result = dk->getText();
1144 break;
1145 }
1146 case STRING:
1147 {
1148 s = LT(1);
1149 match(STRING);
1150 result = s->getText();
1151 break;
1152 }
1153 default:
1154 {
1155 throw antlr::NoViableAltException(LT(1), getFilename());
1156 }
1157 }
1158 }
1159 catch (antlr::RecognitionException& ex) {
1160 reportError(ex);
1161 recover(ex,_tokenSet_17);
1162 }
1163 return result;
1164 }
1165
1166 string RequirementParser::pathstring() {
1167 string result;
1168 antlr::RefToken dk = antlr::nullToken;
1169 antlr::RefToken s = antlr::nullToken;
1170 antlr::RefToken pn = antlr::nullToken;
1171
1172 try { // for error handling
1173 switch ( LA(1)) {
1174 case DOTKEY:
1175 {
1176 dk = LT(1);
1177 match(DOTKEY);
1178 result = dk->getText();
1179 break;
1180 }
1181 case STRING:
1182 {
1183 s = LT(1);
1184 match(STRING);
1185 result = s->getText();
1186 break;
1187 }
1188 case PATHNAME:
1189 {
1190 pn = LT(1);
1191 match(PATHNAME);
1192 result = pn->getText();
1193 break;
1194 }
1195 default:
1196 {
1197 throw antlr::NoViableAltException(LT(1), getFilename());
1198 }
1199 }
1200 }
1201 catch (antlr::RecognitionException& ex) {
1202 reportError(ex);
1203 recover(ex,_tokenSet_9);
1204 }
1205 return result;
1206 }
1207
1208 void RequirementParser::initializeASTFactory( antlr::ASTFactory& )
1209 {
1210 }
1211 const char* RequirementParser::tokenNames[] = {
1212 "<0>",
1213 "EOF",
1214 "<2>",
1215 "NULL_TREE_LOOKAHEAD",
1216 "ARROW",
1217 "\"guest\"",
1218 "\"host\"",
1219 "\"designated\"",
1220 "\"library\"",
1221 "\"plugin\"",
1222 "\"or\"",
1223 "\"and\"",
1224 "LPAREN",
1225 "RPAREN",
1226 "NOT",
1227 "\"always\"",
1228 "\"true\"",
1229 "\"never\"",
1230 "\"false\"",
1231 "\"identifier\"",
1232 "\"cdhash\"",
1233 "\"platform\"",
1234 "\"notarized\"",
1235 "\"anchor\"",
1236 "\"apple\"",
1237 "\"generic\"",
1238 "\"certificate\"",
1239 "\"cert\"",
1240 "\"trusted\"",
1241 "\"info\"",
1242 "\"entitlement\"",
1243 "\"exists\"",
1244 "EQL",
1245 "EQQL",
1246 "STAR",
1247 "SUBS",
1248 "LESS",
1249 "GT",
1250 "LE",
1251 "GE",
1252 "LBRACK",
1253 "RBRACK",
1254 "NEG",
1255 "\"leaf\"",
1256 "\"root\"",
1257 "HASHCONSTANT",
1258 "HEXCONSTANT",
1259 "DOTKEY",
1260 "STRING",
1261 "PATHNAME",
1262 "INTEGER",
1263 "SEMI",
1264 "IDENT",
1265 "HEX",
1266 "COMMA",
1267 "WS",
1268 "SHELLCOMMENT",
1269 "C_COMMENT",
1270 "CPP_COMMENT",
1271 0
1272 };
1273
1274 const unsigned long RequirementParser::_tokenSet_0_data_[] = { 2UL, 0UL, 0UL, 0UL };
1275 // EOF
1276 const antlr::BitSet RequirementParser::_tokenSet_0(_tokenSet_0_data_,4);
1277 const unsigned long RequirementParser::_tokenSet_1_data_[] = { 992UL, 262144UL, 0UL, 0UL };
1278 // "guest" "host" "designated" "library" "plugin" INTEGER
1279 const antlr::BitSet RequirementParser::_tokenSet_1(_tokenSet_1_data_,4);
1280 const unsigned long RequirementParser::_tokenSet_2_data_[] = { 16UL, 0UL, 0UL, 0UL };
1281 // ARROW
1282 const antlr::BitSet RequirementParser::_tokenSet_2(_tokenSet_2_data_,4);
1283 const unsigned long RequirementParser::_tokenSet_3_data_[] = { 994UL, 262144UL, 0UL, 0UL };
1284 // EOF "guest" "host" "designated" "library" "plugin" INTEGER
1285 const antlr::BitSet RequirementParser::_tokenSet_3(_tokenSet_3_data_,4);
1286 const unsigned long RequirementParser::_tokenSet_4_data_[] = { 268447730UL, 1024259UL, 0UL, 0UL };
1287 // EOF ARROW "guest" "host" "designated" "library" "plugin" "or" "and"
1288 // RPAREN "trusted" EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1289 // INTEGER SEMI
1290 const antlr::BitSet RequirementParser::_tokenSet_4(_tokenSet_4_data_,4);
1291 const unsigned long RequirementParser::_tokenSet_5_data_[] = { 9186UL, 786432UL, 0UL, 0UL };
1292 // EOF "guest" "host" "designated" "library" "plugin" RPAREN INTEGER SEMI
1293 const antlr::BitSet RequirementParser::_tokenSet_5(_tokenSet_5_data_,4);
1294 const unsigned long RequirementParser::_tokenSet_6_data_[] = { 994UL, 786432UL, 0UL, 0UL };
1295 // EOF "guest" "host" "designated" "library" "plugin" INTEGER SEMI
1296 const antlr::BitSet RequirementParser::_tokenSet_6(_tokenSet_6_data_,4);
1297 const unsigned long RequirementParser::_tokenSet_7_data_[] = { 10210UL, 786432UL, 0UL, 0UL };
1298 // EOF "guest" "host" "designated" "library" "plugin" "or" RPAREN INTEGER
1299 // SEMI
1300 const antlr::BitSet RequirementParser::_tokenSet_7(_tokenSet_7_data_,4);
1301 const unsigned long RequirementParser::_tokenSet_8_data_[] = { 1828704256UL, 0UL, 0UL, 0UL };
1302 // LPAREN NOT "always" "true" "never" "false" "identifier" "cdhash" "platform"
1303 // "notarized" "anchor" "certificate" "cert" "info" "entitlement"
1304 const antlr::BitSet RequirementParser::_tokenSet_8(_tokenSet_8_data_,4);
1305 const unsigned long RequirementParser::_tokenSet_9_data_[] = { 12258UL, 786432UL, 0UL, 0UL };
1306 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1307 // INTEGER SEMI
1308 const antlr::BitSet RequirementParser::_tokenSet_9(_tokenSet_9_data_,4);
1309 const unsigned long RequirementParser::_tokenSet_10_data_[] = { 0UL, 269312UL, 0UL, 0UL };
1310 // NEG "leaf" "root" INTEGER
1311 const antlr::BitSet RequirementParser::_tokenSet_10(_tokenSet_10_data_,4);
1312 const unsigned long RequirementParser::_tokenSet_11_data_[] = { 0UL, 237827UL, 0UL, 0UL };
1313 // EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1314 const antlr::BitSet RequirementParser::_tokenSet_11(_tokenSet_11_data_,4);
1315 const unsigned long RequirementParser::_tokenSet_12_data_[] = { 0UL, 499712UL, 0UL, 0UL };
1316 // HASHCONSTANT DOTKEY STRING PATHNAME INTEGER
1317 const antlr::BitSet RequirementParser::_tokenSet_12(_tokenSet_12_data_,4);
1318 const unsigned long RequirementParser::_tokenSet_13_data_[] = { 268435456UL, 237827UL, 0UL, 0UL };
1319 // "trusted" EQL EQQL LBRACK HASHCONSTANT DOTKEY STRING PATHNAME
1320 const antlr::BitSet RequirementParser::_tokenSet_13(_tokenSet_13_data_,4);
1321 const unsigned long RequirementParser::_tokenSet_14_data_[] = { 2147495906UL, 1024000UL, 0UL, 0UL };
1322 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1323 // "exists" HASHCONSTANT DOTKEY STRING PATHNAME INTEGER SEMI
1324 const antlr::BitSet RequirementParser::_tokenSet_14(_tokenSet_14_data_,4);
1325 const unsigned long RequirementParser::_tokenSet_15_data_[] = { 2147495906UL, 786683UL, 0UL, 0UL };
1326 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1327 // "exists" EQL EQQL SUBS LESS GT LE GE INTEGER SEMI
1328 const antlr::BitSet RequirementParser::_tokenSet_15(_tokenSet_15_data_,4);
1329 const unsigned long RequirementParser::_tokenSet_16_data_[] = { 12258UL, 786436UL, 0UL, 0UL };
1330 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1331 // STAR INTEGER SEMI
1332 const antlr::BitSet RequirementParser::_tokenSet_16(_tokenSet_16_data_,4);
1333 const unsigned long RequirementParser::_tokenSet_17_data_[] = { 12258UL, 786948UL, 0UL, 0UL };
1334 // EOF "guest" "host" "designated" "library" "plugin" "or" "and" RPAREN
1335 // STAR RBRACK INTEGER SEMI
1336 const antlr::BitSet RequirementParser::_tokenSet_17(_tokenSet_17_data_,4);
1337
1338
1339 ANTLR_END_NAMESPACE