bool key_store_crypto::add_key(const key & k) { std::lock_guard<std::recursive_mutex> l1(mutex_); if (is_crypted() == false) { return key_store_basic::add_key(k); } if (is_locked()) { return false; } std::vector<std::uint8_t> crypted_secret; auto public_key = k.get_public_key(); bool compressed = false; if ( crypter::encrypt_secret(m_master_key, k.get_secret(compressed), public_key.get_hash(), crypted_secret) == false ) { return false; } if (add_crypted_key(k.get_public_key(), crypted_secret) == false) { return false; } return true; }
error_info create_error(int err, const key &id, const char *format, ...) { va_list args; va_start(args, format); const char *id_str = id.by_id() ? dnet_dump_id(&id.id()) : id.remote().c_str(); error_info error = create_info(err, id_str, format, args); va_end(args); return error; }
bool key_store_crypto::get_key( const types::id_key_t & address, key & key_out ) const { std::lock_guard<std::recursive_mutex> l1(mutex_); if (is_crypted() == false) { return key_store_basic::get_key(address, key_out); } auto it = m_crypted_keys.find(address); if (it != m_crypted_keys.end()) { const auto & pub_key = it->second.first; const auto & crypted_secret = it->second.second; key::secret_t s; /** * Decrypt the secret. */ if ( crypter::decrypt_secret(m_master_key, crypted_secret, pub_key.get_hash(), s) == false ) { return false; } if (s.size() != 32) { return false; } /** * Set the public key. */ key_out.set_public_key(pub_key); /** * Set the secret. */ key_out.set_secret(s); return true; } return false; }
void session::write_file(const key &id, const std::string &file, uint64_t local_offset, uint64_t offset, uint64_t size) { transform(id); session sess = clone(); sess.set_exceptions_policy(throw_at_wait); int err; file_descriptor fd(open(file.c_str(), O_RDONLY | O_LARGEFILE | O_CLOEXEC)); if (fd.fd() < 0) { err = -errno; throw_error(err, id, "Failed to open read completion file '%s'", file.c_str()); } struct stat stat; memset(&stat, 0, sizeof(stat)); err = fstat(fd.fd(), &stat); if (err) { err = -errno; throw_error(err, id, "Failed to stat to be written file '%s'", file.c_str()); } if (local_offset >= (uint64_t)stat.st_size) { BH_LOG(get_logger(), DNET_LOG_NOTICE, "%s: File is already uploaded: '%s'", dnet_dump_id(&id.id()), file); return; } if (!size || size + local_offset >= (uint64_t)stat.st_size) size = stat.st_size - local_offset; dnet_io_control ctl; memset(&ctl, 0, sizeof(struct dnet_io_control)); ctl.data = NULL; ctl.fd = fd.fd(); ctl.local_offset = local_offset; memcpy(ctl.io.id, id.id().id, DNET_ID_SIZE); memcpy(ctl.io.parent, id.id().id, DNET_ID_SIZE); ctl.io.size = size; ctl.io.offset = offset; ctl.io.timestamp.tsec = stat.st_mtime; ctl.io.timestamp.tnsec = 0; ctl.id = id.id(); write_data(ctl).wait(); }
int compare_key_key(key va, key vb) { ASSERT(!va->isUndefined()); ASSERT(!vb->isUndefined()); if (m_exec->hadException()) return 1; ArgList arguments; arguments.append(va); arguments.append(vb); double compareResult = call(m_exec, m_compareFunction, m_compareCallType, *m_compareCallData, m_globalThisValue, arguments)->toNumber(m_exec); return (compareResult < 0) ? -1 : 1; // Not passing equality through, because we need to store all values, even if equivalent. }
void VoxSynth::noteOff( key note ) { note.transpose( xpose ); for ( byte i = 0; i < numVox; i++ ) // propagate to all controlled voices if ( vox[i]->keybrd.muted() ) vox[i]->noteOff( note ); }
void session::read_file(const key &id, const std::string &file, uint64_t offset, uint64_t size) { transform(id); session sess = clone(); sess.set_exceptions_policy(throw_at_get); read_result_entry result = sess.read_data(id, offset, size).get_one(); dnet_io_attr *io = result.io_attribute(); int err; file_descriptor fd(open(file.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0644)); if (fd.fd() < 0) { err = -errno; throw_error(err, id, "Failed to open read completion file: '%s'", file.c_str()); } err = pwrite(fd.fd(), result.file().data(), result.file().size(), offset); if (err <= 0) { err = -errno; throw_error(err, id, "Failed to write data into completion file: '%s'", file.c_str()); } BH_LOG(get_logger(), DNET_LOG_NOTICE, "%s: read completed: file: '%s', offset: %llu, size: %llu, status: %d.", dnet_dump_id(&id.id()), file, offset, uint64_t(io->size), int(result.command()->status)); }
char OneVoxSynth::menu( key k ) { switch ( k.position() ) { case 1: return '0'; default: return super::menu(k); } }
char Synth::menu( key k ) { switch ( k.position() ) { case 0: return 'p'; default: return super::menu(k); } }
char Instrument::menu( key k ) { switch ( k.position() ) { case 7: return 'x'; case 8: return 'k'; default: return super::menu( k ); } }
double EqualTemperament::pitch( key k ) { double f = pgm_read_float_near( freq + k.position() ); return f * ( 1 << k.octave() ); }