Esempio n. 1
0
int setScheme(TPMI_DH_OBJECT keyHandle, TPMI_ALG_HASH halg, TPMT_SIG_SCHEME *inScheme)
{
    TPM_ALG_ID type;

    if(getKeyType(keyHandle, &type))
        return -1;

    printf("\nkeyType: 0x%04x\n", type);

    switch(type)
    {
    case TPM_ALG_RSA:
        inScheme->scheme = TPM_ALG_RSASSA;
        inScheme->details.rsassa.hashAlg = halg;
        break;
    case TPM_ALG_KEYEDHASH:
        inScheme->scheme = TPM_ALG_HMAC;
        inScheme->details.hmac.hashAlg = halg;
        break;
    case TPM_ALG_ECC:
        inScheme->scheme = TPM_ALG_ECDSA;
        inScheme->details.ecdsa.hashAlg = halg;
        break;
    case TPM_ALG_SYMCIPHER:
    default:
        return -2;
    }

    return 0;
}
/**************************************************************************************
 * Function Name: openBtree
 *
 * Description:
 *		Open a B+ Tree with given name
 *
 * Parameters:
 * 		BTreeHandle **tree: A pointer to an array of B+ Tree, we will only use the first spot
 * 		char *idxId: Name of the B+ Tree
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Xiaolang Wang <*****@*****.**>
 *
 * History:
 *		Date        Name                                      Content
 *		----------  ----------------------------------------  ------------------------
 *		2015-04-27  Xiaolang Wang <*****@*****.**>     Initialization.
 **************************************************************************************/
RC openBtree(BTreeHandle **tree, char *idxId) {
	// if the file has no access, then return error code to report it
	if (access(idxId, R_OK) != 0 || access(idxId, W_OK) != 0) {
		return RC_TABLE_FILE_NO_ACCESS;
	}

	// Set the name of the file to the Buffer Manager
	BM->pageFile = idxId;

	*tree = (BTreeHandle *) malloc(sizeof(BTreeHandle));
	*tree->idxId = (char *) calloc(strlen(idxId) + 1, sizeof(char));

	// Set the tree structure
	// Store the entry of the Buffer Manager here in the tree structure
	strcpy(tree->idxId, idxId);

	DataType keyType;

	RC rc = getKeyType(*tree, &keyType);

	if (rc != RC_OK) {
		return rc;
	}

	*tree->keyType = keyType;
	*tree->mgmtData = BM;

	BTREE_HANDLE->idxId = idxId;
	BTREE_HANDLE->mgmtData = BM;

	// Store the entry of the tree in the scan_handle structure
	// SCAN_HANDLE->tree = *tree;

	return RC_OK;
}
uint32 
UserLicenceKey::printValue( char* target, 
                            UserConstants::UserLicenceKeyField field ) const
{
   switch ( field ) {
      case UserConstants::USER_LICENCE_KEY_ID :
      case UserConstants::USER_LICENCE_KEY_USERUIN :
         mc2log << error << "UserLicenceKey::printValue asked to print ID "
                << "or userUIN, not supported." << endl;
         MC2_ASSERT( false );
         break;
      case UserConstants::USER_LICENCE_KEY :
         strcat( target, "'" );
         sqlString( target + 1, getLicenceKeyStr().c_str() );
         strcat( target, "'" );
         break;
      case UserConstants::USER_LICENCE_PRODUCT :
         strcat( target, "'" );
         sqlString( target + 1, getProduct() );
         strcat( target, "'" );
         break;
      case UserConstants::USER_LICENCE_KEY_TYPE :
         strcat( target, "'" );
         sqlString( target + 1, getKeyType() );
         strcat( target, "'" );
         break;
      default:
         mc2log << error << "UserLicenceKey::printValue unknown " 
                << "fieldType: " << (int)field << endl;
         break;
   }

   return strlen( target );
}
bool
UserLicenceKey::compare( const UserLicenceKey& o ) const {
   return (getLicenceLength() == o.getLicenceLength() &&
           memcmp( getLicenceKey(), o.getLicenceKey(), 
                   getLicenceLength() ) == 0) &&
      getProduct() == o.getProduct() &&
      getKeyType() == o.getKeyType();
}
uint32
UserLicenceKey::printOldKeyValue( char* target ) const {
   strcat( target, "'" );
   MC2String licenceKey;
   if ( getKeyType() != "imei" ) {
      licenceKey.append( getKeyType() );
      licenceKey.append( ":" );
   }
   licenceKey.append( getLicenceKeyStr() );
   if ( !StringUtility::base64Encode( licenceKey.c_str(), 
                                      target + 1 ) ) 
   {
      mc2log << error << "UserLicenceKey::printValue(): "
             << " Base64 encoding of licence key failed!" << endl; 
      // Discard bad key
      target[ 1 ] = '\0';
   }
   strcat( target, "'" );

   return strlen( target );
}
Esempio n. 6
0
bool pki_key::compare(pki_base *ref)
{
	pki_key *kref = (pki_key *)ref;

	if (kref->getKeyType() != getKeyType())
		return false;
	if (!kref || !kref->key || !key)
		return false;

	int r = EVP_PKEY_cmp(key, kref->key);
	pki_openssl_error();
	return r == 1;
}
Esempio n. 7
0
void PianoKeyBoard::createKeys()
{
    keys_->removeAllObjects();
    
	float x = 0;
    
	for (int i=lowNote_; i<=highNote_; ++i)
	{
        PianoKey *key = new PianoKey();
        
        KEYTYPE type = getKeyType(i);
		Point pt = Point::ZERO ;
		Rect rect;
        
		if (isBlackKey(type))
		{
			pt.x = x - whiteKeyWidth_ + getBlackKeyOffset(i) ;
		}
		else
		{
			pt.x = x ;
			x += whiteKeyWidth_ ;
		}
        
		if (isBlackKey(type))
		{
			rect = Rect(pt.x+20, pt.y+17, blackKeyWidth_, blackKeyHeight_);
		}
		else
		{
			int offset = int(x) - (int(pt.x) + int(whiteKeyWidth_)) ;
            
            offset = (float)1.0/2;
            
			rect = Rect(pt.x+20, pt.y+17, whiteKeyWidth_+offset, whiteKeyHeight_);
		}
		key->note_ = i;
		key->type_ = type;
		key->rect_ = rect;
        
		key->position_ = pt;
		key->down_ = false;
        key->matching_ = false;
        
        keys_->setObject(key, itoa(i));
        
        key->release();
	}
    
}
Esempio n. 8
0
    bool DESFireKey::operator==(const DESFireKey& key) const
    {
        if (!Key::operator==(key))
        {
            return false;
        }
        if (isEmpty() && key.isEmpty())
        {
            return true;
        }

        if (getLength() != key.getLength() || isEmpty() || key.isEmpty())
        {
            return false;
        }

        return (getKeyVersion() == key.getKeyVersion() && getKeyType() == key.getKeyType());
    }
Esempio n. 9
0
void PianoKeyBoard::calculateKeySize(cocos2d::Size size)
{
    int whiteKeyCount = 0 ;
    
	for ( int i=lowNote_; i<=highNote_; ++i )
	{
		if ( !isBlackKey(getKeyType(i)))
		{
			++whiteKeyCount ;
		}
	}
    
	whiteKeyWidth_ = (size.width-42) / whiteKeyCount ;
	whiteKeyHeight_ = 243  ;
	blackKeyWidth_ = whiteKeyWidth_ * 16 /27 ;
	blackKeyHeight_ = 124  ;

}
Esempio n. 10
0
void KeyModel::getValue()
{
	if (keyType == Empty) {
		getKeyType();
	}

	QString command;

	switch (keyType)
	{
	case KeyModel::String:
		command = QString("get %1").arg(keyName);
		break;

	case KeyModel::Hash:		
		command = QString("hgetall %1").arg(keyName);
		break;

	case KeyModel::List:
		command = QString("LRANGE %1 0 -1").arg(keyName);		
		break;

	case KeyModel::Set:
		command = QString("SMEMBERS %1").arg(keyName);				
		break;

	case KeyModel::ZSet:		
		command = QString("ZRANGE %1 0 -1 WITHSCORES").arg(keyName);
		break;
	}	

	if (command.isEmpty()) {
		emit valueLoaded(QVariant(), this);
		return;
	} else {
		connect(db, SIGNAL(responseResieved(const QVariant&, QObject *)),
			this, SIGNAL(valueLoaded(const QVariant&, QObject*)));

		db->addCommand(Command(command, this, dbIndex));
	}
}
Esempio n. 11
0
// Migrate the database to the session
int db2session(sqlite3* db, CK_SESSION_HANDLE hSession, int noPublicKey)
{
	CK_ULONG objectCount;
	int result = 0, rv;
	CK_OBJECT_HANDLE* objects = NULL;
	CK_OBJECT_CLASS ckClass;

	// Get all objects
	objects = getObjects(db, &objectCount);
	if (objects == NULL)
	{
		fprintf(stderr, "ERROR: Could not find any objects in the database.\n");
		return 1;
	}

	// Loop over all objects
	for (unsigned i = 0; i < objectCount; i++)
	{
		ckClass = getObjectClass(objects[i]);

		switch (ckClass)
		{
			case CKO_PUBLIC_KEY:
				if (noPublicKey) continue;
				if (getKeyType(objects[i]) != CKK_RSA)
				{
					fprintf(stderr, "ERROR: Cannot export object %lu. Only supporting RSA keys. "
						"Continuing.\n", objects[i]);
					result = 1;
					break;
				}
				rv = dbRSAPub2session(db, objects[i], hSession);
				if (rv) result = 1;
				break;
			case CKO_PRIVATE_KEY:
				if (getKeyType(objects[i]) != CKK_RSA)
				{
					fprintf(stderr, "ERROR: Cannot export object %lu. Only supporting RSA keys. "
						"Continuing.\n", objects[i]);
					result = 1;
					break;
				}
				rv = dbRSAPriv2session(db, objects[i], hSession);
				if (rv) result = 1;
				break;
			case CKO_VENDOR_DEFINED:
				fprintf(stderr, "ERROR: Could not get the class of object %lu. "
						"Continuing.\n", objects[i]);
				result = 1;
				break;
			default:
				fprintf(stderr, "ERROR: Not supporting class %lu in object %lu. "
						"Continuing.\n", ckClass, objects[i]);
				result = 1;
				break;
		}
	}

	free(objects);

	return result;
}
bool
UserLicenceKey::isIMEIKey() const {
   return getKeyType() == "imei";
}
Esempio n. 13
0
void
RuleParser::getNextToken(const UnicodeString& ruleData,
                         int32_t *ruleIndex,
                         UnicodeString& token,
                         tokenType& type,
                         UErrorCode &status)
{
    int32_t curIndex= *ruleIndex;
    UChar ch;
    tokenType prevType=none;

    if (U_FAILURE(status)) {
        return;
    }
    while (curIndex<ruleData.length()) {
        ch = ruleData.charAt(curIndex);
        if ( !inRange(ch, type) ) {
            status = U_ILLEGAL_CHARACTER;
            return;
        }
        switch (type) {
        case tSpace:
            if ( *ruleIndex != curIndex ) { // letter
                token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
                *ruleIndex=curIndex;
                type=prevType;
                getKeyType(token, type, status);
                return;
            }
            else {
                *ruleIndex=*ruleIndex+1;
            }
            break; // consective space
        case tColon:
        case tSemiColon:
            if ( *ruleIndex != curIndex ) {
                token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
                *ruleIndex=curIndex;
                type=prevType;
                getKeyType(token, type, status);
                return;
            }
            else {
                *ruleIndex=curIndex+1;
                return;
            }
        case tLetter:
             if ((type==prevType)||(prevType==none)) {
                prevType=type;
                break;
             }
             break;
        case tNumber:
             if ((type==prevType)||(prevType==none)) {
                prevType=type;
                break;
             }
             else {
                *ruleIndex=curIndex+1;
                return;
             }
         case tDot:
             if (prevType==none) {  // first dot
                prevType=type;
                continue;
             }
             else {
                 if ( *ruleIndex != curIndex ) {
                    token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
                    *ruleIndex=curIndex;  // letter
                    type=prevType;
                    getKeyType(token, type, status);
                    return;
                 }
                 else {  // two consective dots
                    *ruleIndex=curIndex+2;
                    return;
                 }
             }
         default:
             status = U_UNEXPECTED_TOKEN;
             return;
        }
        curIndex++;
    }
    if ( curIndex>=ruleData.length() ) {
        if ( (type == tLetter)||(type == tNumber) ) {
            token=UnicodeString(ruleData, *ruleIndex, curIndex-*ruleIndex);
            getKeyType(token, type, status);
            if (U_FAILURE(status)) {
                return;
            }
        }
        *ruleIndex = ruleData.length();
    }
}
Esempio n. 14
0
  void instr(SgGlobal* global) {

    // Create the lock and key variables in global scope.
    // In main:
    // EnterScope();
    // lock = getTopLock();
    // key = getTopKey();
    // .... rest of main
    // ExitScope();
    // return;
    // FIXME: Add case where we handle arbitrary exits from main
    // This can be handled similar to the way returns are handled
    // for basic blocks.

    SgScopeStatement* scope = isSgScopeStatement(global);

    // Insert lock and key variables at the top of the global scope
    // lock variable
    std::cout << "VarCounter: " << Util::VarCounter << std::endl;
    SgName lock_name("lock_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    SgVariableDeclaration* lock_var = Util::createLocalVariable(lock_name, getLockType(), NULL, scope);
    // Add declaration at the top of the scope
    scope->prepend_statement(lock_var);

    // key variable
    // **** IMPORTANT: Using same counter value for lock and key
    SgName key_name("key_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    Util::VarCounter++;
    SgVariableDeclaration* key_var = Util::createLocalVariable(key_name, getKeyType(), NULL, scope);
    // Insert this key decl after the lock decl
    SI::insertStatementAfter(lock_var, key_var);


    // Now, find the main function and insert...
    // EnterScope();
    // lock = getTopLock();
    // key = getTopKey();
    // .... rest of main
    // ExitScope()
    // return; -- this already exists...
    // see FIXME above

    // find main function...
    SgFunctionDeclaration* MainFn = SI::findMain(global);
    if(!MainFn) {
#ifdef HANDLE_GLOBAL_SCOPE_DEBUG
      printf("Can't find Main function. Not inserting Global Enter and Exit Scopes\n");
#endif
      return;
    }

    SgBasicBlock *bb = Util::getBBForFn(MainFn);

    // insert EnterScope()
#if 0
    SgExpression* overload = buildOverloadFn("EnterScope", NULL, NULL, SgTypeVoid::createType(), scope,
        GEFD(bb));
#endif
    SgExpression* overload = buildMultArgOverloadFn("EnterScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope,
        GEFD(bb));

    SgStatement* enter_scope = SB::buildExprStatement(overload);
    Util::insertAtTopOfBB(bb, enter_scope);

    // insert lock = getTopLock();
    //overload = buildOverloadFn("getTopLock", NULL, NULL, getLockType(), scope, GEFD(bb));
    overload = buildMultArgOverloadFn("getTopLock", SB::buildExprListExp(), getLockType(), scope, GEFD(bb));
    //SgStatement* lock_assign = SB::buildExprStatement(SB::buildAssignOp(SB::buildVarRefExp(lock_var), overload));
    //SI::insertStatementAfter(enter_scope, lock_assign); //RMM COMMENTED OUT

    // insert key = getTopKey();
    // overload = buildOverloadFn("getTopKey", NULL, NULL, getKeyType(), scope, GEFD(bb));
    overload = buildMultArgOverloadFn("getTopKey", SB::buildExprListExp(), getKeyType(), scope, GEFD(bb));
    //SgStatement* key_assign = SB::buildExprStatement(SB::buildAssignOp(SB::buildVarRefExp(key_var), overload));
    //SI::insertStatementAfter(lock_assign, key_assign); //RMM COMMENTED OUT

    // add to scope -> lock and key map... SLKM
    LockKeyPair lock_key = std::make_pair(lock_var, key_var);
    scopeLockMap[scope] = lock_key;

    ROSE_ASSERT(existsInSLKM(scope));

    // Insert ExitScope if last stmt is not return.
    SgStatementPtrList& stmts = bb->get_statements();
    SgStatementPtrList::iterator it = stmts.begin();
    it += (stmts.size() - 1);

    // A little iffy on the scope part here... lets check that.
    if(!isSgReturnStmt(*it)) {
      // Last statement is not return. So, add exit scope...
      // If its a break/continue statement, insert statement before,
      // otherwise, add exit_scope afterwards.
      //SgExpression* overload = buildOverloadFn("ExitScope", NULL, NULL, SgTypeVoid::createType(), scope, GEFD(bb));
      SgExpression* overload = buildMultArgOverloadFn("ExitScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope, GEFD(bb));

      // check if its break/continue
      if(isSgBreakStmt(*it) || isSgContinueStmt(*it)) {
        SI::insertStatementBefore(*it, SB::buildExprStatement(overload));
      }
      else {
        SI::insertStatementAfter(*it, SB::buildExprStatement(overload));
      }
    }

  }
Esempio n. 15
0
  void instr(SgBasicBlock* bb) {

    // 1. Add Enter Scope -- This will be removed when RTED ScopeGuard is used
    // 2. Insert lock and key variables at the top of stack.
    // 3. Create a map for lock and key with each scope
    // 4. Insert ExitScope statement if the last statement in the list isn't
    // a return stmt. Return stmts are handled in handleReturnStmts

    SgScopeStatement* scope = isSgScopeStatement(bb);

    // 1. Add Enter Scope
#if 0
    SgExpression* overload = buildOverloadFn("EnterScope", NULL, NULL, SgTypeVoid::createType(), scope,
        GEFD(bb));
#endif
    SgExpression* overload = buildMultArgOverloadFn("EnterScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope,
        GEFD(bb));

    SgStatement* enter_scope = SB::buildExprStatement(overload);
    Util::insertAtTopOfBB(bb, enter_scope);

    // 2. Insert lock and key variables
    // lock calls "getTopLock"
    // key calls "getTopKey"
#if 0
    overload = buildOverloadFn("getTopLock", NULL, NULL, getLockType(), scope,
        GEFD(bb));
#endif
    overload = buildMultArgOverloadFn("getTopLock", SB::buildExprListExp(), getLockType(), scope,
        GEFD(bb));
    // **** IMPORTANT: Using same counter value for lock and key
    SgName lock_name("lock_var" + boost::lexical_cast<std::string>(Util::VarCounter));
    //SgVariableDeclaration* lock_var = Util::createLocalVariable(lock_name, getLockType(), overload, scope);
    // Insert this lock declaration after the EnterScope
    //SI::insertStatementAfter(enter_scope, lock_var); //RMM COMMENTED OUT

    // For the key...
#if 0
    overload = buildOverloadFn("getTopKey", NULL, NULL, getKeyType(), scope,
        GEFD(bb));
#endif
    overload = buildMultArgOverloadFn("getTopKey", SB::buildExprListExp(), getKeyType(), scope,
        GEFD(bb));

    // **** IMPORTANT: Using same counter value for lock and key
    SgName key_name("key_var" + boost::lexical_cast<std::string>(Util::VarCounter++));
    //SgVariableDeclaration* key_var = Util::createLocalVariable(key_name, getKeyType(), overload, scope);
    // Insert this key decl after the lock decl
    //SI::insertStatementAfter(lock_var, key_var); //RMM COMMENTED OUT

    // Add to scope -> lock and key map
    //LockKeyPair lock_key = std::make_pair(lock_var, key_var);
    //SLKM[scope] = lock_key;

    //ROSE_ASSERT(existsInSLKM(scope));

    // 4. Insert ExitScope if last stmt is not return.
    SgStatementPtrList& stmts = bb->get_statements();
    SgStatementPtrList::iterator it = stmts.begin();
    it += (stmts.size() - 1);

    if(!isSgReturnStmt(*it)) {
      // Last statement is not return. So, add exit scope...
      // If its a break/continue statement, insert statement before,
      // otherwise, add exit_scope afterwards.
      //SgExpression* overload = buildOverloadFn("ExitScope", NULL, NULL, SgTypeVoid::createType(), scope, GEFD(bb));
      SgExpression* overload = buildMultArgOverloadFn("ExitScope", SB::buildExprListExp(), SgTypeVoid::createType(), scope, GEFD(bb));
      // check if its break/continue
      if(isSgBreakStmt(*it) || isSgContinueStmt(*it)) {
        SI::insertStatementBefore(*it, SB::buildExprStatement(overload));
      }
      else {
        SI::insertStatementAfter(*it, SB::buildExprStatement(overload));
      }
    }

    return;
  }