bool test_feature() { int edata_src[_rank]; int edata_dst[_rank]; for (int i = 1; i < _rank+1; i++) // extent < 1 is not supported { edata_src[i-1] = i+1; printf("src %d %d\n", i, edata_src[i-1]); edata_dst[i-1] = i; printf("dst %d %d\n", i, edata_dst[i-1]); } extent<_rank> esrc(edata_src); extent<_rank> edst(edata_dst); std::vector<_type> data_src(esrc.size()); for (unsigned int i = 0; i < esrc.size(); i++) data_src[i] = (_type)rand(); std::vector<_type> vsrc; std::vector<_type> vdst; { Concurrency::array<_type, _rank> src(esrc, data_src.begin()); Concurrency::array<_type, _rank> dst(edst); src.copy_to(dst); vsrc = src; vdst = dst; if (vdst.size() != vdst.size()) return false; for (size_t i = 0; i < vdst.size(); i++) { if (vdst[i] != vsrc[i]) return false; } } return true; }
void Group::merge_ndattributes(MapNDAttrSrc_t::const_iterator it_begin, MapNDAttrSrc_t::const_iterator it_end, std::set<std::string>& used_ndattribute_srcs) { MapNDAttrSrc_t::const_iterator it; MapDatasets_t::iterator it_dset; for (it = it_begin; it != it_end; ++it){ it_dset = this->datasets.find(it->first); if (it_dset != this->datasets.end()){ DataSource data_src(*it->second); it_dset->second->set_data_source(data_src); used_ndattribute_srcs.insert(it->first); } } // Recursively call the children (groups) of this group to do the same // operation on their datasets. MapGroups_t::iterator it_groups; for (it_groups = this->groups.begin(); it_groups != this->groups.end(); ++it_groups){ it_groups->second->merge_ndattributes(it_begin, it_end, used_ndattribute_srcs); } }
Test::Result PK_Key_Generation_Test::test_key(const std::string& algo, const Botan::Private_Key& key) { Test::Result result(algo + " keygen"); try { Botan::DataSource_Memory data_src(Botan::X509::PEM_encode(key)); std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); result.test_eq("recovered public key from private", loaded.get(), true); result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); } catch(std::exception& e) { result.test_failure("roundtrip PEM public key", e.what()); } try { Botan::DataSource_Memory data_src(Botan::X509::BER_encode(key)); std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); result.test_eq("recovered public key from private", loaded.get(), true); result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); } catch(std::exception& e) { result.test_failure("roundtrip BER public key", e.what()); } try { Botan::DataSource_Memory data_src(Botan::PKCS8::PEM_encode(key)); std::unique_ptr<Botan::Private_Key> loaded( Botan::PKCS8::load_key(data_src, Test::rng())); result.test_eq("recovered private key from PEM blob", loaded.get(), true); result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); } catch(std::exception& e) { result.test_failure("roundtrip PEM private key", e.what()); } try { Botan::DataSource_Memory data_src(Botan::PKCS8::BER_encode(key)); std::unique_ptr<Botan::Public_Key> loaded(Botan::PKCS8::load_key(data_src, Test::rng())); result.test_eq("recovered public key from private", loaded.get(), true); result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); } catch(std::exception& e) { result.test_failure("roundtrip BER private key", e.what()); } const std::string passphrase = Test::random_password(); try { Botan::DataSource_Memory data_src( Botan::PKCS8::PEM_encode(key, Test::rng(), passphrase, std::chrono::milliseconds(10))); std::unique_ptr<Botan::Private_Key> loaded( Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); result.test_eq("recovered private key from encrypted blob", loaded.get(), true); result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); } catch(std::exception& e) { result.test_failure("roundtrip encrypted PEM private key", e.what()); } try { Botan::DataSource_Memory data_src( Botan::PKCS8::BER_encode(key, Test::rng(), passphrase, std::chrono::milliseconds(10))); std::unique_ptr<Botan::Private_Key> loaded( Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); result.test_eq("recovered private key from BER blob", loaded.get(), true); result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); result.test_eq("private key passes checks", loaded->check_key(Test::rng(), false), true); } catch(std::exception& e) { result.test_failure("roundtrip encrypted BER private key", e.what()); } return result; }
std::vector<Test::Result> PK_Key_Generation_Test::run() { std::vector<Test::Result> results; for(auto const& param : keygen_params()) { const std::string report_name = algo_name() + (param.empty() ? param : " " + param); Test::Result result(report_name + " keygen"); const std::vector<std::string> providers = possible_providers(algo_name()); if(providers.empty()) { result.note_missing("provider key generation " + algo_name()); } result.start_timer(); for(auto&& prov : providers) { std::unique_ptr<Botan::Private_Key> key_p = Botan::create_private_key(algo_name(), Test::rng(), param, prov); const Botan::Private_Key& key = *key_p; try { result.confirm("Key passes self tests", key.check_key(Test::rng(), true)); } catch(Botan::Lookup_Error&) {} result.test_gte("Key has reasonable estimated strength (lower)", key.estimated_strength(), 64); result.test_lt("Key has reasonable estimated strength (upper)", key.estimated_strength(), 512); // Test PEM public key round trips OK try { Botan::DataSource_Memory data_src(Botan::X509::PEM_encode(key)); std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); result.confirm("recovered public key from private", loaded.get() != nullptr); result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); try { result.test_eq("public key passes checks", loaded->check_key(Test::rng(), false), true); } catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip PEM public key", e.what()); } // Test DER public key round trips OK try { Botan::DataSource_Memory data_src(Botan::X509::BER_encode(key)); std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src)); result.confirm("recovered public key from private", loaded.get() != nullptr); result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); try { result.confirm("public key passes self tests", loaded->check_key(Test::rng(), true)); } catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip BER public key", e.what()); } // Test PEM private key round trips OK try { Botan::DataSource_Memory data_src(Botan::PKCS8::PEM_encode(key)); std::unique_ptr<Botan::Private_Key> loaded( Botan::PKCS8::load_key(data_src, Test::rng())); result.confirm("recovered private key from PEM blob", loaded.get() != nullptr); result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); try { result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); } catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip PEM private key", e.what()); } try { Botan::DataSource_Memory data_src(Botan::PKCS8::BER_encode(key)); std::unique_ptr<Botan::Public_Key> loaded(Botan::PKCS8::load_key(data_src, Test::rng())); result.confirm("recovered public key from private", loaded.get() != nullptr); result.test_eq("public key has same type", loaded->algo_name(), key.algo_name()); try { result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); } catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip BER private key", e.what()); } #if defined(BOTAN_HAS_PKCS5_PBE2) && defined(BOTAN_HAS_AES) && defined(BOTAN_HAS_SHA2_32) const std::string pbe_algo = "PBE-PKCS5v20(AES-128,SHA-256)"; const std::string passphrase = Test::random_password(); try { Botan::DataSource_Memory data_src( Botan::PKCS8::PEM_encode(key, Test::rng(), passphrase, std::chrono::milliseconds(10), pbe_algo)); std::unique_ptr<Botan::Private_Key> loaded( Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); result.confirm("recovered private key from encrypted blob", loaded.get() != nullptr); result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); try { result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); } catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip encrypted PEM private key", e.what()); } try { Botan::DataSource_Memory data_src( Botan::PKCS8::BER_encode(key, Test::rng(), passphrase, std::chrono::milliseconds(10), pbe_algo)); std::unique_ptr<Botan::Private_Key> loaded( Botan::PKCS8::load_key(data_src, Test::rng(), passphrase)); result.confirm("recovered private key from BER blob", loaded.get() != nullptr); result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name()); try { result.confirm("private key passes self tests", loaded->check_key(Test::rng(), true)); } catch(Botan::Lookup_Error&) {} } catch(std::exception& e) { result.test_failure("roundtrip encrypted BER private key", e.what()); } #endif } result.end_timer(); results.push_back(result); } return results; }