Skip to content

Commit

Permalink
Move makeKeyDerivation, makeHandshakeContext into base Factory implem…
Browse files Browse the repository at this point in the history
…entation

Summary:
Now that the Factory has a pure virtual `makeHasherFactory()` primitive,
`KeyDerivation` and `HandshakeContext` can be expressed in terms of this
primitive.

Reviewed By: zalecodez

Differential Revision: D63283091

fbshipit-source-id: 574edb27d1496ff02c266d144cb3813a524e680e
  • Loading branch information
Mingtao Yang authored and facebook-github-bot committed Oct 1, 2024
1 parent bbd27ee commit 6517498
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
13 changes: 13 additions & 0 deletions fizz/protocol/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ std::unique_ptr<folly::IOBuf> Factory::makeRandomBytes(size_t count) const {
return RandomBufGenerator(count).generateRandom();
}

std::unique_ptr<HandshakeContext> Factory::makeHandshakeContext(
CipherSuite cipher) const {
auto hasherFactory = makeHasherFactory(getHashFunction(cipher));
return std::make_unique<HandshakeContextImpl>(hasherFactory);
}
//

std::unique_ptr<KeyDerivation> Factory::makeKeyDeriver(
CipherSuite cipher) const {
auto hasher = makeHasherFactory(getHashFunction(cipher));
return std::make_unique<KeyDerivationImpl>(hasher);
}

std::shared_ptr<Cert> Factory::makeIdentityOnlyCert(std::string ident) const {
return std::make_shared<IdentityCert>(std::move(ident));
}
Expand Down
4 changes: 2 additions & 2 deletions fizz/protocol/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class Factory {
CipherSuite cipher) const;

virtual std::unique_ptr<KeyDerivation> makeKeyDeriver(
CipherSuite cipher) const = 0;
CipherSuite cipher) const;

virtual std::unique_ptr<HandshakeContext> makeHandshakeContext(
CipherSuite cipher) const = 0;
CipherSuite cipher) const;

virtual std::unique_ptr<KeyExchange> makeKeyExchange(
NamedGroup group,
Expand Down
14 changes: 0 additions & 14 deletions fizz/protocol/MultiBackendFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ std::unique_ptr<Aead> MultiBackendFactory::makeAead(CipherSuite cipher) const {
}
}

// TODO: This belongs in Factory
std::unique_ptr<KeyDerivation> MultiBackendFactory::makeKeyDeriver(
CipherSuite cipher) const {
auto hasher = makeHasherFactory(getHashFunction(cipher));
return std::make_unique<KeyDerivationImpl>(hasher);
}

const HasherFactoryWithMetadata* MultiBackendFactory::makeHasherFactory(
HashFunction digest) const {
switch (digest) {
Expand All @@ -105,13 +98,6 @@ const HasherFactoryWithMetadata* MultiBackendFactory::makeHasherFactory(
}
}

// TODO: This belongs in Factory
std::unique_ptr<HandshakeContext> MultiBackendFactory::makeHandshakeContext(
CipherSuite cipher) const {
auto hasherFactory = makeHasherFactory(getHashFunction(cipher));
return std::make_unique<HandshakeContextImpl>(hasherFactory);
}

std::unique_ptr<PeerCert> MultiBackendFactory::makePeerCert(
CertificateEntry certEntry,
bool /*leaf*/) const {
Expand Down
6 changes: 0 additions & 6 deletions fizz/protocol/MultiBackendFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ class MultiBackendFactory : public Factory {
[[nodiscard]] std::unique_ptr<Aead> makeAead(
CipherSuite cipher) const override;

std::unique_ptr<KeyDerivation> makeKeyDeriver(
CipherSuite cipher) const override;

const HasherFactoryWithMetadata* makeHasherFactory(
HashFunction digest) const override;

std::unique_ptr<HandshakeContext> makeHandshakeContext(
CipherSuite cipher) const override;

[[nodiscard]] std::unique_ptr<PeerCert> makePeerCert(
CertificateEntry certEntry,
bool /*leaf*/) const override;
Expand Down

0 comments on commit 6517498

Please sign in to comment.