1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "config.h" 6 #include "platform/network/ContentSecurityPolicyParsers.h" 7 8 #include "wtf/ASCIICType.h" 9 10 namespace WebCore { 11 12 bool isCSPDirectiveNameCharacter(UChar c) 13 { 14 return isASCIIAlphanumeric(c) || c == '-'; 15 } 16 17 bool isCSPDirectiveValueCharacter(UChar c) 18 { 19 return isASCIISpace(c) || (c >= 0x21 && c <= 0x7e); // Whitespace + VCHAR 20 } 21 22 // Only checks for general Base64 encoded chars, not '=' chars since '=' is 23 // positional and may only appear at the end of a Base64 encoded string. 24 bool isBase64EncodedCharacter(UChar c) 25 { 26 return isASCIIAlphanumeric(c) || c == '+' || c == '/'; 27 } 28 29 bool isNonceCharacter(UChar c) 30 { 31 return isBase64EncodedCharacter(c) || c == '='; 32 } 33 34 bool isSourceCharacter(UChar c) 35 { 36 return !isASCIISpace(c); 37 } 38 39 bool isPathComponentCharacter(UChar c) 40 { 41 return c != '?' && c != '#'; 42 } 43 44 bool isHostCharacter(UChar c) 45 { 46 return isASCIIAlphanumeric(c) || c == '-'; 47 } 48 49 bool isSchemeContinuationCharacter(UChar c) 50 { 51 return isASCIIAlphanumeric(c) || c == '+' || c == '-' || c == '.'; 52 } 53 54 bool isNotASCIISpace(UChar c) 55 { 56 return !isASCIISpace(c); 57 } 58 59 bool isNotColonOrSlash(UChar c) 60 { 61 return c != ':' && c != '/'; 62 } 63 64 bool isMediaTypeCharacter(UChar c) 65 { 66 return !isASCIISpace(c) && c != '/'; 67 } 68 69 } // namespace 70