Ejemplo n.º 1
0
bool checkDigest(const String& source, uint8_t hashAlgorithmsUsed, const CSPDirectiveListVector& policies)
{
    // Any additions or subtractions from this struct should also modify the
    // respective entries in the kSupportedPrefixes array in
    // CSPSourceList::parseHash().
    static const struct {
        ContentSecurityPolicyHashAlgorithm cspHashAlgorithm;
        HashAlgorithm algorithm;
    } kAlgorithmMap[] = {
        { ContentSecurityPolicyHashAlgorithmSha1, HashAlgorithmSha1 },
        { ContentSecurityPolicyHashAlgorithmSha256, HashAlgorithmSha256 },
        { ContentSecurityPolicyHashAlgorithmSha384, HashAlgorithmSha384 },
        { ContentSecurityPolicyHashAlgorithmSha512, HashAlgorithmSha512 }
    };

    // Only bother normalizing the source/computing digests if there are any checks to be done.
    if (hashAlgorithmsUsed == ContentSecurityPolicyHashAlgorithmNone)
        return false;

    StringUTF8Adaptor utf8Source(source);

    for (const auto& algorithmMap : kAlgorithmMap) {
        DigestValue digest;
        if (algorithmMap.cspHashAlgorithm & hashAlgorithmsUsed) {
            bool digestSuccess = computeDigest(algorithmMap.algorithm, utf8Source.data(), utf8Source.length(), digest);
            if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHashValue(algorithmMap.cspHashAlgorithm, digest)))
                return true;
        }
    }

    return false;
}
Ejemplo n.º 2
0
static void convert_out_iso_8859_15(char* out, int out_len, char* in)
{
  BufferCharSource utf8Source(in);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  BufferCharSink outSink(out, out_len);
  InternalEncodingConverterSink sinkToISO_8859_15(InternalEncoding::Unicode20(), ExternalEncoding::ISO_8859_15(), outSink);
  sinkToISO_8859_15.Put(fromUTF8);
}
Ejemplo n.º 3
0
static void convert_out_cp1256(char* out, int out_len, char* in)
{
  BufferCharSource utf8Source(in);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  BufferCharSink outSink(out, out_len);
  InternalEncodingConverterSink sinkToCP1256(InternalEncoding::Unicode20(), ExternalEncoding::CP1256(), outSink);
  sinkToCP1256.Put(fromUTF8);
}
Ejemplo n.º 4
0
void toupper_utf8_string(char *OutputString, char *InputString)
{
int InputString_Length;
InputString_Length = strlen((const char *)InputString);
BufferCharSource utf8Source(InputString,InputString+InputString_Length);
InternalEncodingConverter unicodeSource(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
ToUppercaseTransform toUpper(unicodeSource);    /* DENqa22293: changed for rosette 3.2.0 */
BufferCharSink utf8sink(OutputString, InputString_Length*3);
InternalEncodingConverterSink outsink(InternalEncoding::Unicode20(), ExternalEncoding::Unicode20UTF8(), utf8sink);
outsink.Put(toUpper);
}
Ejemplo n.º 5
0
CString ArbI18N::toFullWidth(char const * s)
{   
  /* we want to ensure the use of full-width numbers and latin text. */
  BufferCharSource utf8Source(s);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  ToFullwidthTransform fullWidth(fromUTF8);
  StringCharSink backToUTF8;
  InternalEncodingConverterSink sinkToUTF8(InternalEncoding::Unicode20(), ExternalEncoding::Unicode20UTF8(), backToUTF8);
  sinkToUTF8.Put(fullWidth);
  CString r = backToUTF8.c_str();
  return r;
}
Ejemplo n.º 6
0
CString ArbI18N::Utf8HankakuToZenkaku(char const * s)
{   
  /* Change Hiragana to Katakana and set all characters to full-width  */
  BufferCharSource	utf8Source(s);
  StringCharSink	utf8Sink;

  InternalEncodingConverter unicodeSource(utf8Source,
      ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  ToUppercaseTransform toU(unicodeSource);
  ToKatakanaTransform toK(toU);
  HankakuKatakanaToZenkakuTransform HtoZ(toK);
  InternalEncodingConverterSink unicodeSink(InternalEncoding::Unicode20(), 
	  ExternalEncoding::Unicode20UTF8(), utf8Sink);
  unicodeSink.Put(HtoZ);
  CString r = utf8Sink.c_str();
  return r;
}