Exemplo n.º 1
0
bool ArgumentCoder<CString>::decode(Decoder& decoder, CString& result)
{
    uint32_t length;
    if (!decoder.decode(length))
        return false;

    if (length == std::numeric_limits<uint32_t>::max()) {
        // This is the null string.
        result = CString();
        return true;
    }

    // Before allocating the string, make sure that the decoder buffer is big enough.
    if (!decoder.bufferIsLargeEnoughToContain<char>(length)) {
        decoder.markInvalid();
        return false;
    }

    char* buffer;
    CString string = CString::newUninitialized(length, buffer);
    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length, 1))
        return false;

    result = string;
    return true;
}
bool Coder<WebCore::CertificateInfo>::decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
{
    bool hasCertificate;
    if (!decoder.decode(hasCertificate))
        return false;

    if (!hasCertificate)
        return true;

    uint64_t size = 0;
    if (!decoder.decode(size))
        return false;

    Vector<uint8_t> vector(size);
    if (!decoder.decodeFixedLengthData(vector.data(), vector.size()))
        return false;

    GByteArray* certificateData = g_byte_array_sized_new(vector.size());
    certificateData = g_byte_array_append(certificateData, vector.data(), vector.size());
    GRefPtr<GByteArray> certificateBytes = adoptGRef(certificateData);

    GTlsBackend* backend = g_tls_backend_get_default();
    GRefPtr<GTlsCertificate> certificate = adoptGRef(G_TLS_CERTIFICATE(g_initable_new(
        g_tls_backend_get_certificate_type(backend), 0, 0, "certificate", certificateBytes.get(), nullptr)));
    certificateInfo.setCertificate(certificate.get());

    uint32_t tlsErrors;
    if (!decoder.decode(tlsErrors))
        return false;
    certificateInfo.setTLSErrors(static_cast<GTlsCertificateFlags>(tlsErrors));

    return true;
}
static bool decodeCFData(Decoder& decoder, RetainPtr<CFDataRef>& data)
{
    uint64_t size = 0;
    if (!decoder.decode(size))
        return false;

    Vector<uint8_t> vector(size);
    if (!decoder.decodeFixedLengthData(vector.data(), vector.size()))
        return false;

    data = adoptCF(CFDataCreate(nullptr, vector.data(), vector.size()));
    return true;
}
bool Coder<WebCore::CertificateInfo>::decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
{
    uint64_t certificateSize;
    if (!decoder.decode(certificateSize))
        return false;
    Vector<uint8_t> data(certificateSize);
    if (!decoder.decodeFixedLengthData(data.data(), data.size()))
        return false;
    IPC::ArgumentDecoder argumentDecoder(data.data(), data.size());
    if (!argumentDecoder.decode(certificateInfo)) {
        decoder.markInvalid();
        return false;
    }
    return true;
}
Exemplo n.º 5
0
static inline bool decodeStringText(Decoder& decoder, uint32_t length, String& result)
{
    // Before allocating the string, make sure that the decoder buffer is big enough.
    if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length)) {
        decoder.markInvalid();
        return false;
    }
    
    CharacterType* buffer;
    String string = String::createUninitialized(length, buffer);
    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType), alignof(CharacterType)))
        return false;
    
    result = string;
    return true;    
}
bool Coder<SHA1::Digest>::decode(Decoder& decoder, SHA1::Digest& digest)
{
    return decoder.decodeFixedLengthData(digest.data(), sizeof(digest));
}