Exemplo n.º 1
0
//! calculate hashes for entire reconstructed picture
Void SEIEncoder::initDecodedPictureHashSEI(SEIDecodedPictureHash *decodedPictureHashSEI, TComPic *pcPic, std::string &rHashString, const BitDepths &bitDepths)
{
  assert (m_isInitialized);
  assert (decodedPictureHashSEI!=NULL);
  assert (pcPic!=NULL);

  if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1)
  {
    decodedPictureHashSEI->method = SEIDecodedPictureHash::MD5;
    UInt numChar=calcMD5(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths);
    rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar);
  }
  else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2)
  {
    decodedPictureHashSEI->method = SEIDecodedPictureHash::CRC;
    UInt numChar=calcCRC(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths);
    rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar);
  }
  else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3)
  {
    decodedPictureHashSEI->method = SEIDecodedPictureHash::CHECKSUM;
    UInt numChar=calcChecksum(*pcPic->getPicYuvRec(), decodedPictureHashSEI->m_pictureHash, bitDepths);
    rHashString = hashToString(decodedPictureHashSEI->m_pictureHash, numChar);
  }
}
Exemplo n.º 2
0
 inline bool compareTwoHashes(uint8_t hashA[32], uint8_t hashB[32])
 {
     char bufA[65];
     char bufB[65];
     hashToString(hashA, bufA);
     hashToString(hashB, bufB);
     std::string strA(bufA);
     std::string strB(bufB);
     if(strA == strB) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
std::string SerializedObject::toString(void) const
	{
	return "SerializedObject<bytes="
		+ boost::lexical_cast<string>(mSerializedData->totalByteCount())
		+ ", valcount=" + boost::lexical_cast<string>(totalValues())
		+ ", hash=" + hashToString(hash()) + ">"
		;
	}
Exemplo n.º 4
0
//----------
void ofxWatermark::init(string filename, string hash) {
	ofFile file(filename);
	auto buffer = file.readToBuffer();
	
	unsigned char fileHash[MD5_DIGEST_LENGTH];
	MD5((unsigned char *)buffer.getBinaryBuffer(), buffer.size(), fileHash);

	if (hashToString(fileHash) != hash) {
		ofSystemAlertDialog("The watermark hash does not match. Tamper alert! Quitting!");
		ofExit();
	}

	this->loadImage(buffer);
}
Exemplo n.º 5
0
void
ModelLayer::setReadOptions(const osgDB::Options* readOptions)
{
    _readOptions = Registry::cloneOrCreateOptions(readOptions);

    // Create some local cache settings for this layer:
    CacheSettings* oldSettings = CacheSettings::get(readOptions);
    _cacheSettings = oldSettings ? new CacheSettings(*oldSettings) : new CacheSettings();

    // bring in the new policy for this layer if there is one:
    _cacheSettings->integrateCachePolicy(_initOptions.cachePolicy());

    // if caching is a go, install a bin.
    if (_cacheSettings->isCacheEnabled())
    {
        std::string binID;
        if (_initOptions.cacheId().isSet() && !_initOptions.cacheId()->empty())
        {
            binID = _initOptions.cacheId().get();
        }
        else
        {
            Config conf = _initOptions.driver()->getConfig();
            binID = hashToString(conf.toJSON(false));
        }

        // make our cacheing bin!
        CacheBin* bin = _cacheSettings->getCache()->addBin(binID);
        if (bin)
        {
            OE_INFO << LC << "Layer " << getName() << " opened cache bin [" << binID << "]\n";
            _cacheSettings->setCacheBin( bin );
        }
        else
        {
            // failed to create the bin, so fall back on no cache mode.
            OE_WARN << LC << "Layer " << getName() << " failed to open a cache bin [" << binID << "], disabling caching\n";
            _cacheSettings->cachePolicy() = CachePolicy::NO_CACHE;
        }
    }

    // Store it for further propagation!
    _cacheSettings->store(_readOptions.get());
}
Exemplo n.º 6
0
bool CudaCompiler::runPreprocessor(std::string& cubinFile, std::string& finalOpts)
{
  // Preprocess.
  finalOpts = "";
  
  if (s_staticOptions.length()) {
    finalOpts += s_staticOptions + " ";
  }
  finalOpts += m_options;

  std::string logFile = m_cachePath + "/preprocess.log";
  
  std::string cmd = s_nvccCommand + " -E -o \"" + m_cachePath + "/preprocessed.cu\" " +
                    "-include \"" + m_cachePath + "/defines.inl\" " + 
                    finalOpts + " \"" + m_sourceFile + 
                    "\" 2>>\"" + logFile + "\"";

  initLogFile( logFile, cmd);
  
  if (0 != system(cmd.c_str()))
  {
    setLoggedError("CudaCompiler: Preprocessing failed!", logFile);
    return false;
  }

  // Specify binary format.
  if (s_staticBinaryFormat.length()) {
    finalOpts += s_staticBinaryFormat;
  } else {
    finalOpts += "-cubin";
  }
  finalOpts += " ";

  
  U32 hashA = FW_HASH_MAGIC;
  U32 hashB = FW_HASH_MAGIC;
  U32 hashC = FW_HASH_MAGIC;
  
  // Override SM architecture.
  S32 smArch = m_overriddenSMArch;
  if (!smArch) {
    smArch = CudaModule::getComputeCapability();
  }

  finalOpts = removeOption(finalOpts, "-arch", true);
  finalOpts = removeOption(finalOpts, "--gpu-architecture", true);
  
  char smArch_str[32];
  sprintf(smArch_str, "-arch sm_%d ", smArch);
  finalOpts += std::string(smArch_str);

  // Override pointer width.
  // CUDA 3.2 => requires -m32 for x86 build and -m64 for x64 build.
  if (CudaModule::getDriverVersion() >= 32)
  {
    finalOpts = removeOption(finalOpts, "-m32", false);
    finalOpts = removeOption(finalOpts, "-m64", false);
    finalOpts = removeOption(finalOpts, "--machine", true);

#if FW_64
    finalOpts += "-m64 ";
#else
    finalOpts += "-m32 ";
#endif
  }
    
  // Hash final compiler options and version.
  hashA += hash<std::string>(finalOpts);
  hashB += s_nvccVersionHash;
  FW_JENKINS_MIX(hashA, hashB, hashC);
  
  // File's timestamp hash to recompile when modified.
  U64 hashD = getFileTimeStamp( m_sourceFile );
  
  std::string fileName = hashToString(hashB) + 
                         hashToString(hashC) +
                         hashToString(hashD);
  
  cubinFile = m_cachePath + "/" + fileName + ".cubin";
  
  return true;
}
Exemplo n.º 7
0
/*
    Render a table from a data grid

    Examples:

        table(grid, "{ refresh:'@update', period:'1000', pivot:'true' }");
        table(grid, "{ click:'@edit' }");
        table(grid, "columns: [ \
            { name: product, header: 'Product', width: '20%' }, \
            { name: date,    format: '%m-%d-%y' }, \
            { name: 'user.name' }, \
        ]");
        table(readTable("users"));
        table(makeGrid("[{'name': 'peter', age: 23 }, {'name': 'mary', age: 22}]")
        table(grid, "{ \
            columns: [ \
                { name: 'speed',         header: 'Speed', dropdown: [100, 1000, 40000] }, \
                { name: 'adminMode',     header: 'Admin Mode', radio: ['Up', 'Down'] }, \
                { name: 'state',         header: 'State', radio: ['Enabled', 'Disabled'] }, \
                { name: 'autoNegotiate', header: 'Auto Negotiate', checkbox: ['enabled'] }, \
                { name: 'type',          header: 'Type' }, \
            ], \
            edit: true, \
            pivot: true, \
            showHeader: false, \
            class: 'esp-pivot', \
        }");

 */
static void pivotTable(HttpConn *conn, EdiGrid *grid, MprHash *options)
{
    MprHash     *colOptions, *rowOptions, *thisCol, *dropdown, *radio;
    MprList     *cols;
    EdiRec      *rec;
    EdiField    *fp;
    cchar       *title, *width, *o, *header, *name, *checkbox;
    char        index[8];
    int         c, r, ncols;
   
    assert(grid);
    if (grid->nrecords == 0) {
        espRender(conn, "<p>No Data</p>\r\n");
        return;
    }
    colOptions = httpGetOptionHash(options, "columns");
    cols = ediGetGridColumns(grid);
    ncols = mprGetListLength(cols);
    rowOptions = mprCreateHash(0, MPR_HASH_STABLE);
    httpSetOption(rowOptions, EDATA("click"), httpGetOption(options, EDATA("click"), 0));
    httpInsertOption(options, "class", ESTYLE("pivot"));
    httpInsertOption(options, "class", ESTYLE("table"));
    espRender(conn, "<table%s>\r\n", map(conn, options));

    /*
        Table header
     */
    if (httpOption(options, "showHeader", "true", 1)) {
        espRender(conn, "    <thead>\r\n");
        if ((title = httpGetOption(options, "title", 0)) != 0) {
            espRender(conn, "        <tr class='" ESTYLE("table-title") "'><td colspan='%s'>%s</td></tr>\r\n", 
                mprGetListLength(cols), title);
        }
        espRender(conn, "        <tr class='" ESTYLE("header") "'>\r\n");
        rec = grid->records[0];
        for (r = 0; r < ncols; r++) {
            assert(r <= grid->nrecords);
            width = ((o = httpGetOption(options, "width", 0)) != 0) ? sfmt(" width='%s'", o) : "";
            thisCol = mprLookupKey(colOptions, itosbuf(index, sizeof(index), r, 10));
            header = httpGetOption(thisCol, "header", spascal(rec->id));
            espRender(conn, "            <th%s>%s</th>\r\n", width, header);
        }
        espRender(conn, "        </tr>\r\n    </thead>\r\n");
    }
    espRender(conn, "    <tbody>\r\n");

    /*
        Table body data
     */
    for (r = 0; r < grid->nrecords; r++) {
        rec = grid->records[r];
        httpSetOption(rowOptions, "id", rec->id);
        espRender(conn, "        <tr%s>\r\n", map(conn, rowOptions));
        for (c = 0; c < ncols; c++) {
            fp = &rec->fields[c];
            thisCol = mprLookupKey(colOptions, itosbuf(index, sizeof(index), r, 10));
            if (httpGetOption(thisCol, "align", 0) == 0) {
                if (fp->type == EDI_TYPE_INT || fp->type == EDI_TYPE_FLOAT) {
                    if (!thisCol) {
                        thisCol = mprCreateHash(0, MPR_HASH_STABLE);
                    }
                    httpInsertOption(thisCol, "align", "right");
                }
            }
            if (c == 0) {
                /* 
                    Render column name
                 */
                name = httpGetOption(thisCol, "header", spascal(rec->id));
                if (httpOption(options, "edit", "true", 0) && httpOption(thisCol, "edit", "true", 1)) {
                    espRender(conn, "            <td%s>%s</td><td>", map(conn, thisCol), name);
                    if ((dropdown = httpGetOption(thisCol, "dropdown", 0)) != 0) {
                        espDropdown(conn, fp->name, hashToGrid(dropdown), 0);
                    } else if ((radio = httpGetOption(thisCol, "radio", 0)) != 0) {
                        espRadio(conn, fp->name, hashToString(radio, 0), 0);
                    } else if ((checkbox = httpGetOption(thisCol, "checkbox", 0)) != 0) {
                        espCheckbox(conn, fp->name, checkbox, 0);
                    } else {
                        input(fp->name, 0);
                    }
                    espRender(conn, "</td>\r\n");
                } else {
                    espRender(conn, "            <td%s>%s</td><td>%s</td>\r\n", map(conn, thisCol), name, fp->value);
                }                
            } else {
                espRender(conn, "            <td%s>%s</td>\r\n", map(conn, thisCol), fp->value);
            }
        }
    }
    espRender(conn, "        </tr>\r\n");
    espRender(conn, "    </tbody>\r\n</table>\r\n");
}
Exemplo n.º 8
0
void CPPMLPrettyPrint<Hash>::prettyPrint(CPPMLPrettyPrintStream& s, const Hash& t)
	{
	s << hashToString(t).substr(0, 12) + "...";
	}
Exemplo n.º 9
0
void hashSHA1(char* string, char* mdString) {
	assert(string); assert(mdString);
	unsigned char digest[SHA_DIGEST_LENGTH] = {0x00,};
	SHA1((unsigned char*) string, strlen(string), digest);
	hashToString(digest, mdString);
}
Exemplo n.º 10
0
void ByteArrayToMpz(mpz_t value, unsigned char* ret) {
	// mpz_import(value, SHA_DIGEST_LENGTH, 1, sizeof(ret[0]), 1, 0, ret);
	char str[SHA_DIGEST_LENGTH*2+1];
	hashToString(ret, str);
	mpz_set_str(value, str, 16);
}