Skip to content

Commit 2a6659a

Browse files
committed
Expose additional helper methods
1 parent 51f5237 commit 2a6659a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

include/ncrypto.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,12 +1790,19 @@ class Aead final : public ModeMixin<Aead> {
17901790
static const Aead FromName(std::string_view name);
17911791

17921792
// TODO(npaun): BoringSSL does not define NIDs for all AEADs.
1793-
// Decide if we will even implement this method.
1794-
// int getNid() const;
1793+
// This method is included only for implementing getCipherInfo and can't be
1794+
// used to construct an Aead instance.
1795+
int getNid() const;
17951796
// static const AEAD FromNid(int nid);
17961797

17971798
static const Aead FromCtx(std::string_view name, const AeadCtxPointer& ctx);
17981799

1800+
using AeadNameCallback = std::function<void(std::string_view name)>;
1801+
1802+
// Iterates the known ciphers if the underlying implementation
1803+
// is able to do so.
1804+
static void ForEach(AeadNameCallback callback);
1805+
17991806
// Utilities to get various AEADs by type.
18001807

18011808
static const Aead EMPTY;

src/ncrypto.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5078,6 +5078,12 @@ std::string_view Aead::getName() const {
50785078
return info_->name;
50795079
}
50805080

5081+
int Aead::getNid() const {
5082+
if (!aead_) return 0;
5083+
5084+
return info_->nid;
5085+
}
5086+
50815087
const Aead Aead::FromConstructor(Aead::AeadConstructor construct) {
50825088
return Aead(&aeadIndex.at(construct), construct());
50835089
}
@@ -5162,6 +5168,12 @@ const std::unordered_map<Aead::AeadConstructor, Aead::AeadInfo>
51625168
.mode = EVP_CIPH_STREAM_CIPHER}},
51635169
};
51645170

5171+
void Aead::ForEach(AeadNameCallback callback) {
5172+
for (const auto& [_, info] : aeadIndex) {
5173+
callback(info.name);
5174+
}
5175+
}
5176+
51655177
const Aead Aead::EMPTY = Aead();
51665178
const Aead Aead::AES_128_GCM = Aead::FromConstructor(EVP_aead_aes_128_gcm);
51675179
const Aead Aead::AES_192_GCM = Aead::FromConstructor(EVP_aead_aes_192_gcm);

0 commit comments

Comments
 (0)