Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cieslarmichal/faker-cxx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: kumar80/faker-cxx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Dec 14, 2024

  1. Adding uuid5 function

    Chandan Kumar committed Dec 14, 2024
    Copy the full SHA
    6d37bca View commit details

Commits on Dec 20, 2024

  1. Refactor UUID generation methods

    Chandan Kumar committed Dec 20, 2024
    Copy the full SHA
    a698bf3 View commit details
  2. Fixed formatting

    Chandan Kumar committed Dec 20, 2024
    Copy the full SHA
    3b8d1f9 View commit details
Showing with 459 additions and 57 deletions.
  1. +12 −0 include/faker-cxx/crypto.h
  2. +59 −22 include/faker-cxx/string.h
  3. +298 −0 src/modules/crypto.cpp
  4. +3 −3 src/modules/internet.cpp
  5. +58 −26 src/modules/string.cpp
  6. +14 −0 tests/modules/crypto_test.cpp
  7. +15 −6 tests/modules/string_test.cpp
12 changes: 12 additions & 0 deletions include/faker-cxx/crypto.h
Original file line number Diff line number Diff line change
@@ -30,4 +30,16 @@ FAKER_CXX_EXPORT std::string sha256(std::optional<std::string> = std::nullopt);
* @endcode
*/
FAKER_CXX_EXPORT std::string md5(std::optional<std::string> = std::nullopt);

/**
* @brief Returns a SHA1 hash of provided data.
*
* @returns SHA1 hash string.
*
* @code
* faker::crypto::sha1("hello world") // "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"
* @endcode
*/
FAKER_CXX_EXPORT std::string sha1(std::optional<std::string> = std::nullopt);

}
81 changes: 59 additions & 22 deletions include/faker-cxx/string.h
Original file line number Diff line number Diff line change
@@ -21,16 +21,6 @@

namespace faker::string
{
enum class Uuid
{
V1, // Version 1: UUIDs using a timestamp and monotonic counter.
V3, // Version 3: UUIDs based on the MD5 hash of some data.
V4, // Version 4: UUIDs with random data.
V5, // Version 5: UUIDs based on the SHA1 hash of some data.
V6, // Version 6: UUIDs using a timestamp and monotonic counter (sortable).
V7, // Version 7: UUIDs using a Unix timestamp (sortable).
V8 // Version 8: UUIDs using user-defined data.
};

enum class StringCasing
{
@@ -80,24 +70,71 @@ FAKER_CXX_EXPORT bool isValidGuarantee(GuaranteeMap& guarantee, std::set<char>&
FAKER_CXX_EXPORT std::string generateAtLeastString(const GuaranteeMap& guarantee);

/**
* @brief Generates an Universally Unique Identifier, defaults to V4.
* @brief Generates a UUID version 1 string.
*
* UUID v1 is generated using the current timestamp, a randomly generated clock sequence,
* and a randomly generated node identifier. The timestamp is offset by the UUID epoch.
*
* @returns UUID v1 string in the standard 8-4-4-4-12 format.
*
* @code
* FAKER_CXX_EXPORT std::string uuid = uuidV1(); // "550e8400-e29b-41d4-a716-446655440000"
* @endcode
*/
FAKER_CXX_EXPORT std::string uuidV1();

/**
* @brief Generates a UUID version 3 string.
*
* UUID v3 is generated by creating a random 16-byte hash and modifying specific bytes
* to conform to the UUID version 3 and variant specifications.
*
* @returns UUID v3 string in the standard 8-4-4-4-12 format.
*
* @code
* FAKER_CXX_EXPORT std::string uuid = uuidV3(); // "d9b2d63d-a233-3de7-8c4b-fb6e96c46e04"
* @endcode
*/
FAKER_CXX_EXPORT std::string uuidV3();

/**
* @brief Generates a UUID version 4 string.
*
* UUID v4 is randomly generated. Specific bytes are modified to ensure compliance
* with the UUID version 4 and variant standards.
*
* @returns UUID v4 string in the standard 8-4-4-4-12 format.
*
* @code
* FAKER_CXX_EXPORT std::string uuid = uuidV4(); // "550e8400-e29b-41d4-a716-446655440000"
* @endcode
*/
FAKER_CXX_EXPORT std::string uuidV4();

/**
* @brief Generates a UUID version 5 string.
*
* UUID v5 is generated using a namespace UUID and a name string. The SHA-1 hash of the
* namespace and name is used to produce the UUID. Specific bytes are modified to conform
* to the UUID version 5 and variant specifications. If no namespace UUID is provided,
* a default value will be used.
*
* @param gen A random number generator (type RandomGenerator)
* @param name The name string used in the UUID generation.
* @param namespaceUuid (Optional) The namespace UUID used in the UUID generation.
* Defaults to "bfd98c8e-48c0-46af-bf44-255d24883f8f".
*
* @returns UUID.
* @returns UUID v5 string in the standard 8-4-4-4-12 format.
*
* @code
* faker::string::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2" // V4
* faker::string::uuid(Uuid::V1) // "04f916a0-af32-11ef-9cd2-0242ac120002"
* faker::string::uuid(Uuid::V3) // "a3bb189e-8bf9-3888-9912-ace4e6543002"
* faker::string::uuid(Uuid::V4) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V5) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V6) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V7) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V8) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* FAKER_CXX_EXPORT std::string uuid1 = uuidV5("example");
* // Uses default namespaceUuid: "bfd98c8e-48c0-46af-bf44-255d24883f8f"
*
* FAKER_CXX_EXPORT std::string uuid2 = uuidV5("example", "550e8400-e29b-41d4-a716-446655440000");
* // Uses provided namespaceUuid
* @endcode
*/
FAKER_CXX_EXPORT std::string uuid(Uuid uuid = Uuid::V4);
FAKER_CXX_EXPORT std::string uuidV5(std::string name,
std::string namespaceUuid = "bfd98c8e-48c0-46af-bf44-255d24883f8f");

/**
* @brief Generates an Universally Unique Lexicographically Sortable Identifier.
Loading