Skip to content

Commit

Permalink
Switch to trailing return type style
Browse files Browse the repository at this point in the history
  • Loading branch information
kimci86 committed Feb 25, 2024
1 parent 37e75ce commit 136cdb6
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 97 deletions.
20 changes: 10 additions & 10 deletions include/Arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Arguments
/// \exception FileError if a file cannot be opened
/// \exception ZipError if a zip entry cannot be opened
/// \exception Data::Error if the loaded data cannot be used to carry out an attack
Data loadData() const;
auto loadData() const -> Data;

std::optional<std::string> cipherFile; ///< File containing the ciphertext
std::optional<std::size_t> cipherIndex; ///< Index of the zip entry containing ciphertext
Expand Down Expand Up @@ -104,7 +104,7 @@ class Arguments
std::size_t maxLength{std::numeric_limits<std::size_t>::max()};

/// Compute the intersection between this interval and the given \a other interval
LengthInterval operator&(const LengthInterval& other) const;
auto operator&(const LengthInterval& other) const -> LengthInterval;
};
/// \copydoc LengthInterval
std::optional<LengthInterval> length;
Expand All @@ -131,7 +131,7 @@ class Arguments
const char** m_current;
const char** const m_end;

bool finished() const;
auto finished() const -> bool;

void parseArgument();

Expand Down Expand Up @@ -165,13 +165,13 @@ class Arguments
help
};

std::string readString(const std::string& description);
Option readOption(const std::string& description);
int readInt(const std::string& description);
std::size_t readSize(const std::string& description);
std::vector<std::uint8_t> readHex(const std::string& description);
std::uint32_t readKey(const std::string& description);
std::vector<std::uint8_t> readCharset();
auto readString(const std::string& description) -> std::string;
auto readOption(const std::string& description) -> Option;
auto readInt(const std::string& description) -> int;
auto readSize(const std::string& description) -> std::size_t;
auto readHex(const std::string& description) -> std::vector<std::uint8_t>;
auto readKey(const std::string& description) -> std::uint32_t;
auto readCharset() -> std::vector<std::uint8_t>;
};

#endif // BKCRACK_ARGUMENTS_HPP
4 changes: 2 additions & 2 deletions include/Attack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Attack
/// \param exhaustive True to try and find all valid keys,
/// false to stop searching after the first one is found
/// \param progress Object to report progress
std::vector<Keys> attack(const Data& data, const std::vector<std::uint32_t>& zi_2_32_vector, int& start,
std::size_t index, int jobs, bool exhaustive, Progress& progress);
auto attack(const Data& data, const std::vector<std::uint32_t>& zi_2_32_vector, int& start, std::size_t index, int jobs,
bool exhaustive, Progress& progress) -> std::vector<Keys>;

#endif // BKCRACK_ATTACK_HPP
8 changes: 4 additions & 4 deletions include/Crc32Tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ class Crc32Tab
{
public:
/// \return CRC32 using a lookup table
static std::uint32_t crc32(std::uint32_t pval, std::uint8_t b)
static auto crc32(std::uint32_t pval, std::uint8_t b) -> std::uint32_t
{
return pval >> 8 ^ instance.crctab[lsb(pval) ^ b];
}

/// \return CRC32^-1 using a lookup table
static std::uint32_t crc32inv(std::uint32_t crc, std::uint8_t b)
static auto crc32inv(std::uint32_t crc, std::uint8_t b) -> std::uint32_t
{
return crc << 8 ^ instance.crcinvtab[msb(crc)] ^ b;
}

/// \return Yi[24,32) from Zi and Z{i-1} using CRC32^-1
static std::uint32_t getYi_24_32(std::uint32_t zi, std::uint32_t zim1)
static auto getYi_24_32(std::uint32_t zi, std::uint32_t zim1) -> std::uint32_t
{
return (crc32inv(zi, 0) ^ zim1) << 24;
}

/// \return Z{i-1}[10,32) from Zi[2,32) using CRC32^-1
static std::uint32_t getZim1_10_32(std::uint32_t zi_2_32)
static auto getZim1_10_32(std::uint32_t zi_2_32) -> std::uint32_t
{
return crc32inv(zi_2_32, 0) & mask<10, 32>; // discard 10 least significant bits
}
Expand Down
8 changes: 4 additions & 4 deletions include/Keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,25 @@ class Keys
void updateBackward(const std::vector<std::uint8_t>& ciphertext, std::size_t current, std::size_t target);

/// \return X value
std::uint32_t getX() const
auto getX() const -> std::uint32_t
{
return x;
}

/// \return Y value
std::uint32_t getY() const
auto getY() const -> std::uint32_t
{
return y;
}

/// \return Z value
std::uint32_t getZ() const
auto getZ() const -> std::uint32_t
{
return z;
}

/// \return the keystream byte derived from the keys
std::uint8_t getK() const
auto getK() const -> std::uint8_t
{
return KeystreamTab::getByte(z);
}
Expand Down
6 changes: 3 additions & 3 deletions include/KeystreamTab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ class KeystreamTab
public:
/// \return the keystream byte ki associated to a Zi value
/// \note Only Zi[2,16) is used
static std::uint8_t getByte(std::uint32_t zi)
static auto getByte(std::uint32_t zi) -> std::uint8_t
{
return instance.keystreamtab[(zi & mask<0, 16>) >> 2];
}

/// \return a vector of Zi[2,16) values having given [10,16) bits
/// such that getByte(zi) is equal to ki
/// \note the vector contains one element on average
static const std::vector<std::uint32_t>& getZi_2_16_vector(std::uint8_t ki, std::uint32_t zi_10_16)
static auto getZi_2_16_vector(std::uint8_t ki, std::uint32_t zi_10_16) -> const std::vector<std::uint32_t>&
{
return instance.keystreaminvfiltertab[ki][(zi_10_16 & mask<0, 16>) >> 10];
}

/// \return true if the vector returned by getZi_2_16_vector is not empty,
/// false otherwise
static bool hasZi_2_16(std::uint8_t ki, std::uint32_t zi_10_16)
static auto hasZi_2_16(std::uint8_t ki, std::uint32_t zi_10_16) -> bool
{
return instance.keystreaminvexists[ki][(zi_10_16 & mask<0, 16>) >> 10];
}
Expand Down
8 changes: 4 additions & 4 deletions include/MultTab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ class MultTab
{
public:
/// \return mult * x using a lookup table
static std::uint32_t getMult(std::uint8_t x)
static auto getMult(std::uint8_t x) -> std::uint32_t
{
return instance.multtab[x];
}

/// \return mult^-1 * x using a lookup table
static std::uint32_t getMultinv(std::uint8_t x)
static auto getMultinv(std::uint8_t x) -> std::uint32_t
{
return instance.multinvtab[x];
}

/// \return a vector of bytes x such that
/// msb(x*mult^-1) is equal to msbprod or msbprod-1
static const std::vector<std::uint8_t>& getMsbProdFiber2(std::uint8_t msbprodinv)
static auto getMsbProdFiber2(std::uint8_t msbprodinv) -> const std::vector<std::uint8_t>&
{
return instance.msbprodfiber2[msbprodinv];
}

/// \return a vector of bytes x such that
/// msb(x*mult^-1) is equal to msbprod, msbprod-1 or msbprod+1
static const std::vector<std::uint8_t>& getMsbProdFiber3(std::uint8_t msbprodinv)
static auto getMsbProdFiber3(std::uint8_t msbprodinv) -> const std::vector<std::uint8_t>&
{
return instance.msbprodfiber3[msbprodinv];
}
Expand Down
2 changes: 1 addition & 1 deletion include/SigintHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SigintHandler
SigintHandler(const SigintHandler& other) = delete;

/// Deleted assignment operator
SigintHandler& operator=(const SigintHandler& other) = delete;
auto operator=(const SigintHandler& other) -> SigintHandler& = delete;
};

#endif // BKCRACK_SIGINTHANDLER_HPP
26 changes: 13 additions & 13 deletions include/Zip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,33 @@ class Zip

/// \brief Get the current entry
/// \pre The iterator must be valid
const Entry& operator*() const
auto operator*() const -> const Entry&
{
return *m_entry;
}

/// \brief Access a member of the current entry
/// \pre The iterator must be valid
const Entry* operator->() const
auto operator->() const -> const Entry*
{
return &(*m_entry);
}

/// \brief Read the next central directory record if any or assign end-of-stream iterator
/// \pre The iterator must be valid
Iterator& operator++();
auto operator++() -> Iterator&;

/// \copydoc operator++
Iterator operator++(int);
auto operator++(int) -> Iterator;

/// Test if iterators are equivalent, i.e. both are end-of-stream or both are valid
bool operator==(const Zip::Iterator& other) const
auto operator==(const Zip::Iterator& other) const -> bool
{
return (m_is == nullptr) == (other.m_is == nullptr);
}

/// Test if iterators are not equivalent
bool operator!=(const Zip::Iterator& other) const
auto operator!=(const Zip::Iterator& other) const -> bool
{
return !(*this == other);
}
Expand All @@ -135,37 +135,37 @@ class Zip
explicit Zip(const std::string& filename);

/// Get an iterator pointing to the first entry
Iterator begin() const
auto begin() const -> Iterator
{
return Iterator{*this};
}

/// Get an end-of-stream iterator
Iterator end() const
auto end() const -> Iterator
{
return Iterator{};
}

/// \brief Get the first entry having the given name
/// \exception Error if the archive does not contain an entry with the given name
Entry operator[](const std::string& name) const;
auto operator[](const std::string& name) const -> Entry;

/// \brief Get the entry at the given index
/// \exception Error if the index is out of bounds
Entry operator[](std::size_t index) const;
auto operator[](std::size_t index) const -> Entry;

/// \brief Check that the given entry uses the expected encryption algorithm
/// \exception Error if the given entry does not use the expected encryption algorithm
static void checkEncryption(const Entry& entry, Encryption expected);

/// \brief Set the underlying stream's input position indicator at the beginning the given entry's raw data
/// \exception Error if the given entry's data is not at the expected offset
std::istream& seek(const Entry& entry) const;
auto seek(const Entry& entry) const -> std::istream&;

/// \brief Load at most \a count bytes of the given entry's raw data
/// \exception Error if the given entry's data is not at the expected offset
std::vector<std::uint8_t> load(const Entry& entry,
std::size_t count = std::numeric_limits<std::size_t>::max()) const;
auto load(const Entry& entry, std::size_t count = std::numeric_limits<std::size_t>::max()) const
-> std::vector<std::uint8_t>;

/// \brief Copy the zip file into \a os changing the encrypted data using the given keys
/// \exception Error if the archive is not a valid zip archive
Expand Down
4 changes: 2 additions & 2 deletions include/Zreduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class Zreduction
void generate();

/// \return the generated Zi[2,32) values
const std::vector<std::uint32_t>& getCandidates() const;
auto getCandidates() const -> const std::vector<std::uint32_t>&;

/// \return the index of the Zi[2,32) values relative to keystream
std::size_t getIndex() const;
auto getIndex() const -> std::size_t;

private:
const std::vector<std::uint8_t>& keystream;
Expand Down
8 changes: 4 additions & 4 deletions include/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class FileError : public BaseError

/// \brief Open an input file stream
/// \exception FileError if the file cannot be opened
std::ifstream openInput(const std::string& filename);
auto openInput(const std::string& filename) -> std::ifstream;

/// Load at most \a size bytes from an input stream
std::vector<std::uint8_t> loadStream(std::istream& is, std::size_t size);
auto loadStream(std::istream& is, std::size_t size) -> std::vector<std::uint8_t>;

/// \brief Load at most \a size bytes from a file
/// \exception FileError if the file cannot be opened
std::vector<std::uint8_t> loadFile(const std::string& filename, std::size_t size);
auto loadFile(const std::string& filename, std::size_t size) -> std::vector<std::uint8_t>;

/// \brief Open an output file stream
/// \exception FileError if the file cannot be opened
std::ofstream openOutput(const std::string& filename);
auto openOutput(const std::string& filename) -> std::ofstream;

#endif // BKCRACK_FILE_HPP
4 changes: 2 additions & 2 deletions include/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
/// \brief Output stream manipulators

/// Insert the current local time into the output stream
std::ostream& put_time(std::ostream& os);
auto put_time(std::ostream& os) -> std::ostream&;

class Keys; // forward declaration

/// \brief Insert a representation of keys into the stream \a os
/// \relates Keys
std::ostream& operator<<(std::ostream& os, const Keys& keys);
auto operator<<(std::ostream& os, const Keys& keys) -> std::ostream&;

#endif // BKCRACK_LOG_HPP
6 changes: 3 additions & 3 deletions include/password.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class Recovery
/// \return A vector of passwords associated with the given keys.
/// A vector is needed instead of a single string because there can be
/// collisions (i.e. several passwords for the same keys).
std::vector<std::string> recoverPassword(const Keys& keys, const std::vector<std::uint8_t>& charset,
std::size_t minLength, std::size_t maxLength, std::string& start, int jobs,
bool exhaustive, Progress& progress);
auto recoverPassword(const Keys& keys, const std::vector<std::uint8_t>& charset, std::size_t minLength,
std::size_t maxLength, std::string& start, int jobs, bool exhaustive, Progress& progress)
-> std::vector<std::string>;

#endif // BKCRACK_PASSWORD_HPP
4 changes: 2 additions & 2 deletions include/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class BaseError : public std::runtime_error
// utility functions

/// \return the least significant byte of x
constexpr std::uint8_t lsb(std::uint32_t x)
constexpr auto lsb(std::uint32_t x) -> std::uint8_t
{
return x;
}

/// \return the most significant byte of x
constexpr std::uint8_t msb(std::uint32_t x)
constexpr auto msb(std::uint32_t x) -> std::uint8_t
{
return x >> 24;
}
Expand Down
Loading

0 comments on commit 136cdb6

Please sign in to comment.