コード例 #1
0
ファイル: datastor.cpp プロジェクト: Andrew-He/botan
/*
* Get a single atom
*/
std::string Data_Store::get1(const std::string& key) const
   {
   std::vector<std::string> vals = get(key);

   if(vals.empty())
      throw Invalid_State("Data_Store::get1: No values set for " + key);
   if(vals.size() > 1)
      throw Invalid_State("Data_Store::get1: More than one value for " + key);

   return vals[0];
   }
コード例 #2
0
/*************************************************
* Peek into a stream                             *
*************************************************/
u32bit DataSource_Stream::peek(byte out[], u32bit length, u32bit offset) const
   {
   if(end_of_data())
      throw Invalid_State("DataSource_Stream: Cannot peek when out of data");

   u32bit got = 0;

   if(offset)
      {
      SecureVector<byte> buf(offset);
      source->read((char*)buf.begin(), buf.size());
      if(source->bad())
         throw Stream_IO_Error("DataSource_Stream::peek: Source failure");
      got = source->gcount();
      }

   if(got == offset)
      {
      source->read((char*)out, length);
      if(source->bad())
         throw Stream_IO_Error("DataSource_Stream::peek: Source failure");
      got = source->gcount();
      }

   if(source->eof())
      source->clear();
   source->seekg(total_read, std::ios::beg);

   return got;
   }
コード例 #3
0
ファイル: ecc_key.cpp プロジェクト: Amaterasu27/miktex
/********************************
* EC_PrivateKey
********************************/
void EC_PrivateKey::affirm_init() const // virtual
   {
   if(m_private_value == 0)
      throw Invalid_State("cannot use EC_PrivateKey when private key is uninitialized");

   EC_PublicKey::affirm_init();
   }
コード例 #4
0
ファイル: ecc_key.cpp プロジェクト: Amaterasu27/miktex
const PointGFp& EC_PublicKey::public_point() const
   {
   if(!mp_public_point.get())
      throw Invalid_State("EC_PublicKey::public_point(): public point not set");

   return *mp_public_point;
   }
コード例 #5
0
ファイル: dl_group.cpp プロジェクト: Andrew-He/botan
/*
* Return the subgroup
*/
const BigInt& DL_Group::get_q() const
   {
   init_check();
   if(m_q == 0)
      throw Invalid_State("DLP group has no q prime specified");
   return m_q;
   }
コード例 #6
0
ファイル: libstate.cpp プロジェクト: AlekSi/Jabbin
/*************************************************
* Set the configuration object                   *
*************************************************/
Config& Library_State::config() const
   {
   if(!config_obj)
      throw Invalid_State("Library_State::config(): No config set");

   return (*config_obj);
   }
コード例 #7
0
ファイル: asn1_eac_tm.cpp プロジェクト: Kampbell/botan
/*
* Return a string representation of the time
*/
std::string EAC_Time::as_string() const
   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::as_string: No time set");

   return std::to_string(year * 10000 + month * 100 + day);
   }
コード例 #8
0
ファイル: pk_filts.cpp プロジェクト: BenjaminSchiborr/safe
/*
* Verify the message
*/
void PK_Verifier_Filter::end_msg()
   {
   if(signature.empty())
      throw Invalid_State("PK_Verifier_Filter: No signature to check against");
   bool is_valid = verifier->check_signature(signature);
   send((is_valid ? 1 : 0));
   }
コード例 #9
0
ファイル: data_src.cpp プロジェクト: Stautob/botan
/*
* Peek into a stream
*/
size_t DataSource_Stream::peek(byte out[], size_t length, size_t offset) const
   {
   if(end_of_data())
      throw Invalid_State("DataSource_Stream: Cannot peek when out of data");

   size_t got = 0;

   if(offset)
      {
      secure_vector<byte> buf(offset);
      source.read(reinterpret_cast<char*>(&buf[0]), buf.size());
      if(source.bad())
         throw Stream_IO_Error("DataSource_Stream::peek: Source failure");
      got = source.gcount();
      }

   if(got == offset)
      {
      source.read(reinterpret_cast<char*>(out), length);
      if(source.bad())
         throw Stream_IO_Error("DataSource_Stream::peek: Source failure");
      got = source.gcount();
      }

   if(source.eof())
      source.clear();
   source.seekg(total_read, std::ios::beg);

   return got;
   }
コード例 #10
0
ファイル: tss.cpp プロジェクト: louiz/botan
byte RTSS_Share::share_id() const
   {
   if(!initialized())
      throw Invalid_State("RTSS_Share::share_id not initialized");

   return m_contents[20];
   }
コード例 #11
0
ファイル: ecc_key.cpp プロジェクト: ChrisBFX/botan
const BigInt& EC_PrivateKey::private_value() const
   {
   if(m_private_key == 0)
      throw Invalid_State("EC_PrivateKey::private_value - uninitialized");

   return m_private_key;
   }
コード例 #12
0
ファイル: pipe.cpp プロジェクト: binary1248/SFNUL
void Pipe::prepend_filter(Filter* filter)
   {
   if(m_outputs->message_count() != 0)
      throw Invalid_State("Cannot call Pipe::prepend_filter after start_msg");

   do_prepend(filter);
   }
コード例 #13
0
/*************************************************
* Deallocation                                   *
*************************************************/
void Pooling_Allocator::deallocate(void* ptr, u32bit n)
   {
   const u32bit BITMAP_SIZE = Memory_Block::bitmap_size();
   const u32bit BLOCK_SIZE = Memory_Block::block_size();

   if(ptr == 0 && n == 0)
      return;

   Mutex_Holder lock(mutex);

   if(n > BITMAP_SIZE * BLOCK_SIZE)
      dealloc_block(ptr, n);
   else
      {
      const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE;

      std::vector<Memory_Block>::iterator i =
         std::lower_bound(blocks.begin(), blocks.end(), Memory_Block(ptr));

      if(i == blocks.end() || !i->contains(ptr, block_no))
         throw Invalid_State("Pointer released to the wrong allocator");

      i->free(ptr, block_no);
      }
   }
コード例 #14
0
ファイル: ecc_key.cpp プロジェクト: Amaterasu27/miktex
const BigInt& EC_PrivateKey::private_value() const
   {
   if(m_private_value == 0)
      throw Invalid_State("cannot use EC_PrivateKey when private key is uninitialized");

   return m_private_value;
   }
コード例 #15
0
ファイル: x509_crl.cpp プロジェクト: evpo/EncryptPad
const CRL_Data& X509_CRL::data() const
   {
   if(!m_data)
      {
      throw Invalid_State("X509_CRL uninitialized");
      }
   return *m_data.get();
   }
コード例 #16
0
ファイル: x509cert.cpp プロジェクト: scogliani/botan
const X509_Certificate_Data& X509_Certificate::data() const
   {
   if(m_data == nullptr)
      {
      throw Invalid_State("X509_Certificate uninitialized");
      }
   return *m_data.get();
   }
コード例 #17
0
ファイル: ecc_key.cpp プロジェクト: Amaterasu27/miktex
const EC_Domain_Params& EC_PublicKey::domain_parameters() const
   {
   if(!mp_dom_pars.get())
      throw Invalid_State("EC_PublicKey::domain_parameters(): "
                          "ec domain parameters are not yet set");

   return *mp_dom_pars;
   }
コード例 #18
0
ファイル: pipe.cpp プロジェクト: Amaterasu27/miktex
/*
* Reset the Pipe
*/
void Pipe::reset()
   {
   if(inside_msg)
      throw Invalid_State("Pipe cannot be reset while it is processing");
   destruct(pipe);
   pipe = 0;
   inside_msg = false;
   }
コード例 #19
0
const CRL_Entry_Data& CRL_Entry::data() const
   {
   if(!m_data)
      {
      throw Invalid_State("CRL_Entry_Data uninitialized");
      }

   return *m_data.get();
   }
コード例 #20
0
/*
* Create a new Client Hello message (session resumption case)
*/
Client_Hello::Client_Hello(Handshake_IO& io,
                           Handshake_Hash& hash,
                           const Policy& policy,
                           RandomNumberGenerator& rng,
                           const std::vector<uint8_t>& reneg_info,
                           const Session& session,
                           const std::vector<std::string>& next_protocols) :
   m_version(session.version()),
   m_session_id(session.session_id()),
   m_random(make_hello_random(rng, policy)),
   m_suites(policy.ciphersuite_list(m_version, (session.srp_identifier() != ""))),
   m_comp_methods(policy.compression())
   {
   if(!value_exists(m_suites, session.ciphersuite_code()))
      m_suites.push_back(session.ciphersuite_code());

   if(!value_exists(m_comp_methods, session.compression_method()))
      m_comp_methods.push_back(session.compression_method());

   /*
   We always add the EMS extension, even if not used in the original session.
   If the server understands it and follows the RFC it should reject our resume
   attempt and upgrade us to a new session with the EMS protection.
   */
   m_extensions.add(new Extended_Master_Secret);

   m_extensions.add(new Renegotiation_Extension(reneg_info));
   m_extensions.add(new Server_Name_Indicator(session.server_info().hostname()));
   m_extensions.add(new Session_Ticket(session.session_ticket()));
   m_extensions.add(new Supported_Elliptic_Curves(policy.allowed_ecc_curves()));

   if(!policy.allowed_ecc_curves().empty())
      {
      m_extensions.add(new Supported_Point_Formats(policy.use_ecc_point_compression()));
      }

   if(session.supports_encrypt_then_mac())
      m_extensions.add(new Encrypt_then_MAC);

#if defined(BOTAN_HAS_SRP6)
   m_extensions.add(new SRP_Identifier(session.srp_identifier()));
#else
   if(!session.srp_identifier().empty())
      {
      throw Invalid_State("Attempting to resume SRP session but TLS-SRP support disabled");
      }
#endif

   if(m_version.supports_negotiable_signature_algorithms())
      m_extensions.add(new Signature_Algorithms(policy.allowed_signature_hashes(),
                                                policy.allowed_signature_methods()));

   if(reneg_info.empty() && !next_protocols.empty())
      m_extensions.add(new Application_Layer_Protocol_Notification(next_protocols));

   hash.update(io.send(*this));
   }
コード例 #21
0
ファイル: libstate.cpp プロジェクト: AlekSi/Jabbin
/*************************************************
* Transcode a string from one charset to another *
*************************************************/
std::string Library_State::transcode(const std::string str,
                                     Character_Set to,
                                     Character_Set from) const
   {
   if(!transcoder)
      throw Invalid_State("Library_State::transcode: No transcoder set");

   return transcoder->transcode(str, to, from);
   }
コード例 #22
0
ファイル: ecc_key.cpp プロジェクト: Amaterasu27/miktex
void EC_PrivateKey::PKCS8_load_hook(bool)
   {
   // we cannot use affirm_init() here because mp_public_point might still be null
   if(mp_dom_pars.get() == 0)
      throw Invalid_State("attempt to set public point for an uninitialized key");

   mp_public_point.reset(new PointGFp(m_private_value * mp_dom_pars->get_base_point()));
   mp_public_point->check_invariants();
   }
コード例 #23
0
ファイル: thread_pool.cpp プロジェクト: mgierlings/botan
void Thread_Pool::queue_thunk(std::function<void ()> fn)
   {
   std::unique_lock<std::mutex> lock(m_mutex);

   if(m_shutdown)
      throw Invalid_State("Cannot add work after thread pool has shut down");

   m_tasks.push_back(fn);
   m_more_tasks.notify_one();
   }
コード例 #24
0
ファイル: pipe.cpp プロジェクト: AlexNk/botan
/*
* Start a new message
*/
void Pipe::start_msg()
   {
   if(inside_msg)
      throw Invalid_State("Pipe::start_msg: Message was already started");
   if(pipe == nullptr)
      pipe = new Null_Filter;
   find_endpoints(pipe);
   pipe->new_msg();
   inside_msg = true;
   }
コード例 #25
0
ファイル: pipe.cpp プロジェクト: binary1248/SFNUL
/*
* Pop a Filter off the Pipe
*/
void Pipe::pop()
   {
   if(m_inside_msg)
      throw Invalid_State("Cannot pop off a Pipe while it is processing");

   if(!m_pipe)
      return;

   if(m_pipe->total_ports() > 1)
      throw Invalid_State("Cannot pop off a Filter with multiple ports");

   size_t to_remove = m_pipe->owns() + 1;

   while(to_remove--)
      {
      std::unique_ptr<Filter> to_destroy(m_pipe);
      m_pipe = m_pipe->m_next[0];
      }
   }
コード例 #26
0
ファイル: tss.cpp プロジェクト: mgierlings/botan
uint8_t RTSS_Share::share_id() const
   {
   if(!initialized())
      throw Invalid_State("RTSS_Share::share_id not initialized");

   if(m_contents.size() < RTSS_HEADER_SIZE + 1)
      throw Decoding_Error("RTSS_Share::share_id invalid share data");

   return m_contents[20];
   }
コード例 #27
0
ファイル: der_enc.cpp プロジェクト: evpo/EncryptPad
/*
* Finish the current ASN.1 SEQUENCE/SET/EXPLICIT
*/
DER_Encoder& DER_Encoder::end_cons()
   {
   if(m_subsequences.empty())
      throw Invalid_State("DER_Encoder::end_cons: No such sequence");

   DER_Sequence last_seq = std::move(m_subsequences[m_subsequences.size()-1]);
   m_subsequences.pop_back();
   last_seq.push_contents(*this);

   return (*this);
   }
コード例 #28
0
ファイル: asn1_eac_tm.cpp プロジェクト: Kampbell/botan
/*
* Return a human readable string representation
*/
std::string EAC_Time::readable_string() const
   {
   if(time_is_set() == false)
      throw Invalid_State("EAC_Time::readable_string: No time set");

   // desired format: "%04d/%02d/%02d"
   std::stringstream output;
   output << std::setfill('0')
          << std::setw(4) << year << "/"
          << std::setw(2) << month << "/"
          << std::setw(2) << day;
   return output.str();
   }
コード例 #29
0
ファイル: datastor.cpp プロジェクト: Andrew-He/botan
/*
* Get a single u32bit atom
*/
u32bit Data_Store::get1_u32bit(const std::string& key,
                               u32bit default_val) const
   {
   std::vector<std::string> vals = get(key);

   if(vals.empty())
      return default_val;
   else if(vals.size() > 1)
      throw Invalid_State("Data_Store::get1_u32bit: Multiple values for " +
                          key);

   return to_u32bit(vals[0]);
   }
コード例 #30
0
ファイル: pipe.cpp プロジェクト: AlexNk/botan
/*
* Pop a Filter off the Pipe
*/
void Pipe::pop()
   {
   if(inside_msg)
      throw Invalid_State("Cannot pop off a Pipe while it is processing");

   if(!pipe)
      return;

   if(pipe->total_ports() > 1)
      throw Invalid_State("Cannot pop off a Filter with multiple ports");

   Filter* f = pipe;
   size_t owns = f->owns();
   pipe = pipe->next[0];
   delete f;

   while(owns--)
      {
      f = pipe;
      pipe = pipe->next[0];
      delete f;
      }
   }