Ejemplo n.º 1
0
Archivo: zfile.c Proyecto: DeanHH/czmq
char *
zfile_digest (zfile_t *self)
{
    if (!self->digest) {
        if (zfile_input (self) == -1)
            return NULL;            //  Problem reading file

        //  Now calculate hash for file data, chunk by chunk
        size_t blocksz = 65535;
        off_t offset = 0;

        self->digest = zdigest_new ();
        zchunk_t *chunk = zfile_read (self, blocksz, offset);
        while (zchunk_size (chunk)) {
            zdigest_update (self->digest,
                zchunk_data (chunk), zchunk_size (chunk));
            zchunk_destroy (&chunk);
            offset += blocksz;
            chunk = zfile_read (self, blocksz, offset);
        }
        zchunk_destroy (&chunk);
        zfile_close (self);
    }
    return zdigest_string (self->digest);
}
Ejemplo n.º 2
0
const char *
zfile_digest (zfile_t *self)
{
    assert (self);
    if (!self->digest) {
        if (zfile_input (self) == -1)
            return NULL;            //  Problem reading file

        //  Now calculate hash for file data, chunk by chunk
        size_t blocksz = 65535;
        off_t offset = 0;

        self->digest = zdigest_new ();
        if (!self->digest)
            return NULL;
        zchunk_t *chunk = zfile_read (self, blocksz, offset);
        while (zchunk_size (chunk)) {
            zdigest_update (self->digest,
                            zchunk_data (chunk), zchunk_size (chunk));
            zchunk_destroy (&chunk);

            //  off_t is defined as long (32 bit on Windows, 64 bit otherwise)
            //  This guards against overflow in both contexts.
            if (blocksz > LONG_MAX - offset)
                return NULL;

            offset += (off_t) blocksz;
            chunk = zfile_read (self, blocksz, offset);
        }
        zchunk_destroy (&chunk);
        fclose (self->handle);
        self->handle = 0;
    }
    return zdigest_string (self->digest);
}
Ejemplo n.º 3
0
const char *
hydra_post_ident (hydra_post_t *self)
{
    assert (self);
    zdigest_t *digest = zdigest_new ();
    if (digest) {
        char *digest_text = zsys_sprintf ("%s:%s:%s:%s:%s",
            self->subject, self->timestamp, self->parent_id,
            self->mime_type? self->mime_type: "", self->digest);
        zdigest_update (digest, (byte *) digest_text, strlen (digest_text));
        assert (strlen (zdigest_string (digest)) == ID_SIZE);
        strcpy (self->ident, zdigest_string (digest));
        zstr_free (&digest_text);
        zdigest_destroy (&digest);
    }
    return self->ident;
}
Ejemplo n.º 4
0
///
//  Return digest as printable hex string; caller should not modify nor   
//  free this string. After calling this, you may not use zdigest_update()
//  on the same digest. If built without crypto support, returns NULL.    
const QString QmlZdigest::string () {
    return QString (zdigest_string (self));
};