├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Directory.Build.props ├── LICENSE ├── README.md ├── appveyor.yml ├── src ├── Vlingo.Xoom.UUID.Tests │ ├── NameBasedGeneratorTests.cs │ ├── RandomBasedGeneratorTests.cs │ ├── TimeBasedGeneratorTests.cs │ └── Vlingo.Xoom.UUID.Tests.csproj ├── Vlingo.Xoom.UUID.sln ├── Vlingo.Xoom.UUID.sln.licenseheader └── Vlingo.Xoom.UUID │ ├── ByteMarker.cs │ ├── GuidExtensions.cs │ ├── GuidGenerationMode.cs │ ├── HashType.cs │ ├── NameBasedGenerator.cs │ ├── RandomBasedGenerator.cs │ ├── TimeBasedGenerator.cs │ ├── UUIDNameSpace.cs │ ├── UUIDVersion.cs │ └── Vlingo.Xoom.UUID.csproj └── vlingo-64x64.png /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | os: [ ubuntu-latest, windows-latest, macOS-latest ] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Setup .NET 6.0.x 20 | id: setup-dotnet6 21 | uses: actions/setup-dotnet@v1 22 | with: 23 | dotnet-version: 6.0.x 24 | - name: Restore dependencies 25 | id: restore-deps 26 | run: dotnet restore ./src/Vlingo.Xoom.UUID.sln 27 | - name: Build 28 | id: build 29 | run: dotnet build ./src/Vlingo.Xoom.UUID.sln --no-restore 30 | - name: Test 31 | id: test 32 | run: dotnet test ./src/Vlingo.Xoom.UUID.Tests/Vlingo.Xoom.UUID.Tests.csproj --no-build --verbosity normal 33 | - name: slack - GitHub Actions Slack integration 34 | uses: act10ns/slack@v1.2.2 35 | env: 36 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} 37 | with: 38 | status: ${{ job.status }} 39 | steps: ${{ toJson(steps) }} 40 | if: always() -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | 244 | # SQL Server files 245 | *.mdf 246 | *.ldf 247 | *.ndf 248 | 249 | # Business Intelligence projects 250 | *.rdl.data 251 | *.bim.layout 252 | *.bim_*.settings 253 | *.rptproj.rsuser 254 | 255 | # Microsoft Fakes 256 | FakesAssemblies/ 257 | 258 | # GhostDoc plugin setting file 259 | *.GhostDoc.xml 260 | 261 | # Node.js Tools for Visual Studio 262 | .ntvs_analysis.dat 263 | node_modules/ 264 | 265 | # Visual Studio 6 build log 266 | *.plg 267 | 268 | # Visual Studio 6 workspace options file 269 | *.opt 270 | 271 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 272 | *.vbw 273 | 274 | # Visual Studio LightSwitch build output 275 | **/*.HTMLClient/GeneratedArtifacts 276 | **/*.DesktopClient/GeneratedArtifacts 277 | **/*.DesktopClient/ModelManifest.xml 278 | **/*.Server/GeneratedArtifacts 279 | **/*.Server/ModelManifest.xml 280 | _Pvt_Extensions 281 | 282 | # Paket dependency manager 283 | .paket/paket.exe 284 | paket-files/ 285 | 286 | # FAKE - F# Make 287 | .fake/ 288 | 289 | # JetBrains Rider 290 | .idea/ 291 | *.sln.iml 292 | 293 | # CodeRush 294 | .cr/ 295 | 296 | # Python Tools for Visual Studio (PTVS) 297 | __pycache__/ 298 | *.pyc 299 | 300 | # Cake - Uncomment if you are using it 301 | # tools/** 302 | # !tools/packages.config 303 | 304 | # Tabs Studio 305 | *.tss 306 | 307 | # Telerik's JustMock configuration file 308 | *.jmconfig 309 | 310 | # BizTalk build output 311 | *.btp.cs 312 | *.btm.cs 313 | *.odx.cs 314 | *.xsd.cs 315 | 316 | # OpenCover UI analysis results 317 | OpenCover/ 318 | 319 | # Azure Stream Analytics local run output 320 | ASALocalRun/ 321 | 322 | # MSBuild Binary and Structured Log 323 | *.binlog 324 | 325 | # NVidia Nsight GPU debugger configuration file 326 | *.nvuser 327 | 328 | # MFractors (Xamarin productivity tool) working folder 329 | .mfractor/ 330 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at vaughn@kalele.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute to the vlingo/common 2 | 3 | #### **Did you find a bug?** 4 | 5 | * Make sure the bug was not already reported here: [Issues](https://github.com/vlingo-net/vlingo-net-uuid/issues). 6 | 7 | * If nonexisting, open a new issue for the problem: [Open New Issue](https://github.com/vlingo-net/vlingo-net-uuid/issues/new). Always provide a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. 8 | 9 | #### **Patches and bug fixes** 10 | 11 | * Open a new GitHub pull request with the patch. 12 | 13 | * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. 14 | 15 | * It would be really nice if your followed the basic code format used prevelently. 16 | 17 | #### **Please don't reformat existing code** 18 | 19 | * Just because you don't like a given code style doesn't mean you have the authority to change it. Cosmeic changes add zero to little value. 20 | 21 | #### **New features and enhancements** 22 | 23 | * Email your post your suggestion and provide an example implementation. 24 | 25 | * After agreement open a PR or issue. 26 | 27 | #### **Direct questions to...** 28 | 29 | * Vaughn Vernon: vaughn at kalele dot io 30 | 31 | #### **Contribute to documentation** 32 | 33 | * Vaughn Vernon: vaughn at kalele dot io 34 | 35 | Thanks for your kind assistance! :smile: 36 | 37 | Vaughn Vernon and the Vlingo .NET team 38 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.10.1 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | © under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xoom-net-uuid 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/930yr1mojead52ec?svg=true)](https://ci.appveyor.com/project/VlingoNetOwner/xoom-net-uuid) 4 | ![Build master](https://github.com/vlingo-net/xoom-net-uuid/workflows/.NET/badge.svg) 5 | [![NuGet](https://img.shields.io/nuget/v/Vlingo.Xoom.UUID.svg)](https://www.nuget.org/packages/Vlingo.UUID) 6 | [![Gitter](https://badges.gitter.im/vlingo-platform-net/community.svg)](https://gitter.im/vlingo-platform-net/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 7 | 8 | .NET implementation of UUID generation according to [RFC4122](https://tools.ietf.org/html/rfc4122) spec. 9 | 10 | 11 | License (See LICENSE file for full license) 12 | ------------------------------------------- 13 | Copyright © 2012-2023 VLINGO LABS. All rights reserved. 14 | 15 | This Source Code Form is subject to the terms of the 16 | Mozilla Public License, v. 2.0. If a copy of the MPL 17 | was not distributed with this file, You can obtain 18 | one at https://mozilla.org/MPL/2.0/. -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.10.1.{build} 2 | image: 3 | - Visual Studio 2022 4 | - Ubuntu 5 | - macOS 6 | - macOS-Monterey 7 | - macOS-Bigsur 8 | configuration: Release 9 | skip_commits: 10 | message: /.*\[ci\-skip\].*/ 11 | before_build: 12 | - dotnet restore src/Vlingo.Xoom.UUID.sln 13 | build: 14 | project: src/Vlingo.Xoom.UUID.sln 15 | verbosity: minimal 16 | publish_nuget: true 17 | test_script: 18 | - dotnet test src/Vlingo.Xoom.UUID.Tests 19 | deploy: 20 | - provider: NuGet 21 | api_key: 22 | secure: 4VJZEFZNaDrk3FJmRSmBW+wQugDoPi6DtVlsLZ+26IOo+wb0u9JlnTOTQF+NXs2s 23 | skip_symbols: true 24 | artifact: /.*\.nupkg/ 25 | on: 26 | branch: master 27 | notifications: 28 | - provider: Webhook 29 | url: https://webhooks.gitter.im/e/37621a855e91c31ab1da 30 | method: POST 31 | on_build_success: true 32 | on_build_failure: true 33 | on_build_status_changed: true 34 | -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID.Tests/NameBasedGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using System; 9 | using Xunit; 10 | 11 | namespace Vlingo.Xoom.UUID.Tests; 12 | 13 | public class NameBasedGeneratorTests 14 | { 15 | [Theory] 16 | [InlineData(HashType.Md5)] 17 | [InlineData(HashType.Sha1)] 18 | public void GeneratedUUID_ShouldHaveProperVersion(HashType hashType) 19 | { 20 | var name = Guid.NewGuid().ToString(); 21 | var nameSpace = Guid.NewGuid(); 22 | 23 | var expectedVersion = hashType == HashType.Md5 ? 0x30 : 0x50; 24 | 25 | using (var generator = new NameBasedGenerator(hashType)) 26 | { 27 | var guid = generator.GenerateGuid(nameSpace, name); 28 | 29 | var array = guid.ToActuallyOrderedBytes(); 30 | 31 | Assert.Equal(expectedVersion, array[6] & 0xf0); 32 | } 33 | } 34 | 35 | [Theory] 36 | [InlineData(HashType.Md5, UUIDNameSpace.None)] 37 | [InlineData(HashType.Md5, UUIDNameSpace.Dns)] 38 | [InlineData(HashType.Md5, UUIDNameSpace.Oid)] 39 | [InlineData(HashType.Md5, UUIDNameSpace.Url)] 40 | [InlineData(HashType.Md5, UUIDNameSpace.X500)] 41 | [InlineData(HashType.Sha1, UUIDNameSpace.None)] 42 | [InlineData(HashType.Sha1, UUIDNameSpace.Dns)] 43 | [InlineData(HashType.Sha1, UUIDNameSpace.Oid)] 44 | [InlineData(HashType.Sha1, UUIDNameSpace.Url)] 45 | [InlineData(HashType.Sha1, UUIDNameSpace.X500)] 46 | public void UUIDGenerated_InSameNameAndNameSpace_InDifferentTimes_ShouldBeSame(HashType hashType, UUIDNameSpace nameSpace) 47 | { 48 | var name = Guid.NewGuid().ToString(); 49 | using(var generator = new NameBasedGenerator(hashType)) 50 | { 51 | var first = generator.GenerateGuid(nameSpace, name); 52 | var second = generator.GenerateGuid(nameSpace, name); 53 | 54 | Assert.Equal(first, second); 55 | } 56 | } 57 | 58 | [Theory] 59 | [InlineData(HashType.Md5, UUIDNameSpace.None)] 60 | [InlineData(HashType.Md5, UUIDNameSpace.Dns)] 61 | [InlineData(HashType.Md5, UUIDNameSpace.Oid)] 62 | [InlineData(HashType.Md5, UUIDNameSpace.Url)] 63 | [InlineData(HashType.Md5, UUIDNameSpace.X500)] 64 | [InlineData(HashType.Sha1, UUIDNameSpace.None)] 65 | [InlineData(HashType.Sha1, UUIDNameSpace.Dns)] 66 | [InlineData(HashType.Sha1, UUIDNameSpace.Oid)] 67 | [InlineData(HashType.Sha1, UUIDNameSpace.Url)] 68 | [InlineData(HashType.Sha1, UUIDNameSpace.X500)] 69 | public void UUIDGenerated_InSameNameSpace_WithDifferentNames_ShouldBeDifferent(HashType hashType, UUIDNameSpace nameSpace) 70 | { 71 | var firstName = Guid.NewGuid().ToString(); 72 | var secondName = Guid.NewGuid().ToString(); 73 | using (var generator = new NameBasedGenerator(hashType)) 74 | { 75 | var first = generator.GenerateGuid(nameSpace, firstName); 76 | var second = generator.GenerateGuid(nameSpace, secondName); 77 | 78 | Assert.NotEqual(first, second); 79 | } 80 | } 81 | 82 | [Theory] 83 | [InlineData(HashType.Md5, UUIDNameSpace.Dns, UUIDNameSpace.None)] 84 | [InlineData(HashType.Md5, UUIDNameSpace.None, UUIDNameSpace.Oid)] 85 | [InlineData(HashType.Md5, UUIDNameSpace.Oid, UUIDNameSpace.Url)] 86 | [InlineData(HashType.Md5, UUIDNameSpace.Url, UUIDNameSpace.X500)] 87 | [InlineData(HashType.Sha1, UUIDNameSpace.Dns, UUIDNameSpace.None)] 88 | [InlineData(HashType.Sha1, UUIDNameSpace.None, UUIDNameSpace.Oid)] 89 | [InlineData(HashType.Sha1, UUIDNameSpace.Oid, UUIDNameSpace.Url)] 90 | [InlineData(HashType.Sha1, UUIDNameSpace.Url, UUIDNameSpace.X500)] 91 | public void UUIDGenerated_InWithSameName_InDifferentStandardNameSpace_ShouldBeDifferent( 92 | HashType hashType, 93 | UUIDNameSpace firstNs, 94 | UUIDNameSpace secondNs) 95 | { 96 | var name = Guid.NewGuid().ToString(); 97 | using (var generator = new NameBasedGenerator(hashType)) 98 | { 99 | var first = generator.GenerateGuid(firstNs, name); 100 | var second = generator.GenerateGuid(secondNs, name); 101 | 102 | Assert.NotEqual(first, second); 103 | } 104 | } 105 | 106 | [Theory] 107 | [InlineData(HashType.Md5)] 108 | [InlineData(HashType.Sha1)] 109 | public void UUIDGenerated_InWithSameName_InDifferentCustomNameSpace_ShouldBeDifferent(HashType hashType) 110 | { 111 | var name = Guid.NewGuid().ToString(); 112 | var firstNs = Guid.NewGuid(); 113 | var secondNs = Guid.NewGuid(); 114 | 115 | using (var generator = new NameBasedGenerator(hashType)) 116 | { 117 | var first = generator.GenerateGuid(firstNs, name); 118 | var second = generator.GenerateGuid(secondNs, name); 119 | 120 | Assert.NotEqual(first, second); 121 | } 122 | } 123 | 124 | [Fact] 125 | public void UUIDGenerated_ShouldGenerateProperNamebasedGuid_ForCustomNamespaceAndName() 126 | { 127 | // bugfix for issue: https://github.com/vlingo-net/vlingo-net-uuid/issues/7 128 | 129 | var uuidNamespace = Guid.Parse("a4405a8d-8bb2-467a-bbc3-961ab93bb538"); 130 | var name = "9912310000"; 131 | 132 | var generator = new NameBasedGenerator(HashType.Sha1); 133 | var uuidV5 = generator.GenerateGuid(uuidNamespace, name); 134 | 135 | Assert.Equal("a045c4bc-d81c-5fc4-88bd-313db5b2d1fc", uuidV5.ToString()); 136 | } 137 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID.Tests/RandomBasedGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using Xunit; 9 | 10 | namespace Vlingo.Xoom.UUID.Tests; 11 | 12 | public class RandomBasedGeneratorTests 13 | { 14 | [Fact] 15 | public void GeneratedUUID_ShouldHaveProperVersion() 16 | { 17 | var generator = new RandomBasedGenerator(); 18 | var expectedVersion = 0x40; 19 | 20 | var guid = generator.GenerateGuid(); 21 | var array = guid.ToActuallyOrderedBytes(); 22 | 23 | Assert.Equal(expectedVersion, array[6] & 0xf0); 24 | } 25 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID.Tests/TimeBasedGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using Xunit; 9 | 10 | namespace Vlingo.Xoom.UUID.Tests; 11 | 12 | public class TimeBasedGeneratorTests 13 | { 14 | [Theory] 15 | [InlineData(GuidGenerationMode.FasterGeneration)] 16 | [InlineData(GuidGenerationMode.WithUniquenessGuarantee)] 17 | public void GeneratedUUID_ShouldHaveProperVersion(GuidGenerationMode mode) 18 | { 19 | var generator = new TimeBasedGenerator(); 20 | var expectedVersion = 0x10; 21 | 22 | var guid = generator.GenerateGuid(mode); 23 | var array = guid.ToActuallyOrderedBytes(); 24 | 25 | Assert.Equal(expectedVersion, array[6] & 0xf0); 26 | } 27 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID.Tests/Vlingo.Xoom.UUID.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | latest 6 | Debug;Release;Debug With Project References 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | all 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | 17 | 18 | all 19 | runtime; build; native; contentfiles; analyzers 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vlingo.Xoom.UUID", "Vlingo.Xoom.UUID\Vlingo.Xoom.UUID.csproj", "{D3361751-1B20-40CC-8C63-C08EFF64DB21}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vlingo.Xoom.UUID.Tests", "Vlingo.Xoom.UUID.Tests\Vlingo.Xoom.UUID.Tests.csproj", "{A5E124ED-6418-4F2F-B08A-3E0129E44233}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D3361751-1B20-40CC-8C63-C08EFF64DB21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {D3361751-1B20-40CC-8C63-C08EFF64DB21}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {D3361751-1B20-40CC-8C63-C08EFF64DB21}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {D3361751-1B20-40CC-8C63-C08EFF64DB21}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {A5E124ED-6418-4F2F-B08A-3E0129E44233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A5E124ED-6418-4F2F-B08A-3E0129E44233}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A5E124ED-6418-4F2F-B08A-3E0129E44233}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {A5E124ED-6418-4F2F-B08A-3E0129E44233}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {C7F17CB4-D063-4E81-AC83-767EAB2C9B28} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID.sln.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: .cs 2 | // Copyright (c) 2012-2021 VLINGO LABS. All rights reserved. 3 | // 4 | // This Source Code Form is subject to the terms of the 5 | // Mozilla Public License, v. 2.0. If a copy of the MPL 6 | // was not distributed with this file, You can obtain 7 | // one at https://mozilla.org/MPL/2.0/. 8 | -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/ByteMarker.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using System; 9 | 10 | namespace Vlingo.Xoom.UUID; 11 | 12 | internal static class ByteMarker 13 | { 14 | private const int VariantIndexPosition = 8; 15 | private const int VariantMask = 0x3f; 16 | private const int VariantBits = 0x80; 17 | private const int VersionIndexPosition = 6; 18 | private const int VersionMask = 0x0f; 19 | 20 | /// 21 | /// Sets the first two bits of the 8th (0-based index) byte to binary '10' 22 | /// 23 | /// The array to modify in place 24 | /// The modified 25 | public static byte[] AddVariantMarker(this byte[] array) 26 | { 27 | array[VariantIndexPosition] &= VariantMask; 28 | array[VariantIndexPosition] |= VariantBits; 29 | return array; 30 | } 31 | 32 | /// 33 | /// Sets the 4 most significant bits of 7th (0-based index) byte to the version number 34 | /// 35 | /// The array to modify in place 36 | /// The UUID version 37 | /// The modified 38 | public static byte[] AddVersionMarker(this byte[] array, UUIDVersion version) 39 | { 40 | var versionBits = (byte)version; 41 | array[VersionIndexPosition] &= VersionMask; 42 | array[VersionIndexPosition] |= versionBits; 43 | return array; 44 | } 45 | 46 | public static byte[] TrimTo16Bytes(this byte[] array) 47 | { 48 | var result = new byte[16]; 49 | Array.Copy(array, result, 16); 50 | return result; 51 | } 52 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/GuidExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using System; 9 | 10 | namespace Vlingo.Xoom.UUID; 11 | 12 | public static class GuidExtensions 13 | { 14 | /// 15 | /// Converts the Guid into the byte order as they appear in Guid string 16 | /// 17 | /// 18 | /// Reference: https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray?view=netcore-3.1#remarks 19 | /// 20 | /// 21 | /// Array of bytes 22 | public static byte[] ToActuallyOrderedBytes(this Guid guid) 23 | { 24 | var array = guid.ToByteArray(); 25 | ChangeGuidByteOrders(array); 26 | return array; 27 | } 28 | 29 | /// 30 | /// Converts the byte array so that it appears in the Guid string in the same order 31 | /// Caution: mutates the actual array to save memory 32 | /// 33 | /// 34 | /// Reference: https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray?view=netcore-3.1#remarks 35 | /// 36 | /// 37 | /// A Guid 38 | public static Guid ToGuidFromActuallyOrderedBytes(this byte[] array) 39 | { 40 | ChangeGuidByteOrders(array); 41 | return new Guid(array); 42 | } 43 | 44 | public static long ToLeastSignificantBits(this Guid id) 45 | { 46 | var bytes = id.ToByteArray(); 47 | ChangeGuidByteOrders(bytes); 48 | var boolArray = new bool[bytes.Length]; 49 | for(var i = 0; i < bytes.Length; i++) 50 | { 51 | boolArray[i] = GetBit(bytes[i]); 52 | } 53 | 54 | return BitConverter.ToInt64(bytes, 0); 55 | } 56 | 57 | public static Guid ToGuid(this long id) 58 | { 59 | var data = new byte[16]; 60 | var sourceArray = BitConverter.GetBytes(id); 61 | Array.Copy(sourceArray, data, sourceArray.Length); 62 | return ToGuidFromActuallyOrderedBytes(data); 63 | } 64 | 65 | /// 66 | /// Swaps bytes in positions as: 67 | /// 3, 1 <-> 2, 4 <-> 5, 6 <-> 7]]> 68 | /// 69 | /// 70 | private static void ChangeGuidByteOrders(byte[] array) 71 | { 72 | var temp = array[0]; 73 | array[0] = array[3]; 74 | array[3] = temp; 75 | 76 | temp = array[1]; 77 | array[1] = array[2]; 78 | array[2] = temp; 79 | 80 | temp = array[4]; 81 | array[4] = array[5]; 82 | array[5] = temp; 83 | 84 | temp = array[6]; 85 | array[6] = array[7]; 86 | array[7] = temp; 87 | } 88 | 89 | private static bool GetBit(byte b) => (b & 1) != 0; 90 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/GuidGenerationMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | 9 | namespace Vlingo.Xoom.UUID; 10 | 11 | public enum GuidGenerationMode 12 | { 13 | FasterGeneration = 1, 14 | WithUniquenessGuarantee = 2 15 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/HashType.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | namespace Vlingo.Xoom.UUID; 9 | 10 | public enum HashType 11 | { 12 | Md5 = 1, 13 | Sha1 = 2 14 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/NameBasedGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using System; 9 | using System.Security.Cryptography; 10 | using System.Text; 11 | 12 | namespace Vlingo.Xoom.UUID; 13 | 14 | /// 15 | /// Name based UUID generator according to RFC4122. 16 | /// This is capable of generating Version-3 (with MD5 hashing) 17 | /// and Version-5 (with SHA-1 hashing) variants of RFC4122 UUID. 18 | /// 19 | public sealed class NameBasedGenerator : IDisposable 20 | { 21 | private static readonly Guid[] NameSpaceGuids = { 22 | Guid.Empty, 23 | Guid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), // DNS 24 | Guid.Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8"), // URL 25 | Guid.Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"), // IOD 26 | Guid.Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8") // X500 27 | }; 28 | 29 | private HashAlgorithm? _hashAlgorithm; 30 | private readonly UUIDVersion _version; 31 | 32 | /// 33 | /// Creates an instance of name based RFC4122 UUID generator. 34 | /// Either Version-3 (MD5 hashing) or Version-5 (SHA-1 hashing) variant is instantiated based on . 35 | /// 36 | /// Hashing algorithm type be used (MD5 or SHA-1) 37 | public NameBasedGenerator(HashType hashType) 38 | { 39 | _hashAlgorithm = hashType == HashType.Md5 ? (HashAlgorithm)MD5.Create() : SHA1.Create(); 40 | _version = hashType == HashType.Md5 ? UUIDVersion.NameBasedWithMd5 : UUIDVersion.NamedBasedWithSha1; 41 | } 42 | 43 | /// 44 | /// Creates an instance of name based RFC4122 UUID Version-3 generator, using MD5 hashing. 45 | /// 46 | public NameBasedGenerator() 47 | : this(HashType.Md5) 48 | { 49 | } 50 | 51 | /// 52 | /// Generates RFC4122 name based UUID without any namespace for the given 53 | /// 54 | /// The name to use when generating UUID 55 | /// RFC4122 UUID generated using the 56 | public Guid GenerateGuid(string name) => GenerateGuid(UUIDNameSpace.None, name); 57 | 58 | /// 59 | /// Generates RFC4122 name based UUID with the given and 60 | /// 61 | /// RFC4122 suggested standard namespace for the UUID, or None 62 | /// The name to use when generating UUID 63 | /// RFC4122 UUID generated using the and the 64 | public Guid GenerateGuid(UUIDNameSpace nameSpace, string name) => GenerateGuid(NameSpaceGuids[(int)nameSpace], name); 65 | 66 | /// 67 | /// Generates RFC4122 name based UUID with the given and 68 | /// 69 | /// The custom namespace (as GUID) to use when generating UUID 70 | /// The name to use when generating UUID 71 | /// RFC4122 UUID generated using the and the 72 | public Guid GenerateGuid(Guid customNamespaceGuid, string name) 73 | { 74 | var nsBytes = Guid.Empty == customNamespaceGuid ? new byte[0] : customNamespaceGuid.ToActuallyOrderedBytes(); 75 | var nameBytes = Encoding.UTF8.GetBytes(name); 76 | var data = new byte[nsBytes.Length + nameBytes.Length]; 77 | if(nsBytes.Length > 0) 78 | { 79 | Array.Copy(nsBytes, data, nsBytes.Length); 80 | } 81 | Array.Copy(nameBytes, 0, data, nsBytes.Length, nameBytes.Length); 82 | 83 | var result = _hashAlgorithm! 84 | .ComputeHash(data) 85 | .TrimTo16Bytes() 86 | .AddVariantMarker() 87 | .AddVersionMarker(_version); 88 | 89 | return result.ToGuidFromActuallyOrderedBytes(); 90 | } 91 | 92 | public void Dispose() 93 | { 94 | if (_hashAlgorithm != null) 95 | { 96 | _hashAlgorithm.Dispose(); 97 | _hashAlgorithm = null; 98 | } 99 | } 100 | 101 | ~NameBasedGenerator() 102 | { 103 | _hashAlgorithm?.Dispose(); 104 | } 105 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/RandomBasedGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using System; 9 | using System.Security.Cryptography; 10 | 11 | namespace Vlingo.Xoom.UUID; 12 | 13 | /// 14 | /// Random number based UUID generator according to RFC4122 (version-4) 15 | /// 16 | public class RandomBasedGenerator 17 | { 18 | private readonly RandomNumberGenerator _generator; 19 | 20 | /// 21 | /// Creates an instance of random number based UUID generator according to RFC4122 (version-4) using the provided random number generator. 22 | /// 23 | /// The random number generator. 24 | public RandomBasedGenerator(RandomNumberGenerator generator) => _generator = generator; 25 | 26 | /// 27 | /// Creates an instance of random number based UUID generator according to RFC4122 (version-4). 28 | /// It uses as the random number generator. 29 | /// 30 | public RandomBasedGenerator() : this(RandomNumberGenerator.Create()) 31 | { 32 | } 33 | 34 | /// 35 | /// Generates a RFC4122 random number based UUID (version-4) 36 | /// 37 | /// 38 | public Guid GenerateGuid() 39 | { 40 | var data = new byte[16]; 41 | _generator.GetBytes(data); 42 | 43 | data.AddVariantMarker().AddVersionMarker(UUIDVersion.Random); 44 | 45 | return data.ToGuidFromActuallyOrderedBytes(); 46 | } 47 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/TimeBasedGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | using System; 9 | using System.Net.NetworkInformation; 10 | using System.Security.Cryptography; 11 | using System.Threading; 12 | 13 | namespace Vlingo.Xoom.UUID; 14 | 15 | /// 16 | /// Time based UUID (Version-1) generator according to RFC4122. 17 | /// 18 | public sealed class TimeBasedGenerator 19 | { 20 | private static readonly RandomNumberGenerator RandomGenerator = RandomNumberGenerator.Create(); 21 | private static readonly DateTimeOffset ClockStart = new DateTimeOffset(1582, 10, 15, 0, 0, 0, TimeSpan.Zero); 22 | 23 | private readonly byte[] _macAddressBytes; 24 | private readonly ReaderWriterLock _rwLock; 25 | private readonly object _mutex; 26 | 27 | private DateTimeOffset _lastClockSyncedAt; 28 | private byte[] _currentClockSequenceBytes; 29 | 30 | /// 31 | /// Creates an instance of RFC4122 time based UUID generator, using the IEEE 802 MAC address (6 bytes) provided as node. 32 | /// 33 | /// 6 bytes IEEE 802 MAC address to use as node 34 | public TimeBasedGenerator(byte[] macAddressBytes) 35 | { 36 | _macAddressBytes = macAddressBytes; 37 | _lastClockSyncedAt = DateTimeOffset.UtcNow; 38 | _rwLock = new ReaderWriterLock(); 39 | _mutex = new object(); 40 | _currentClockSequenceBytes = GetRandomBytes(2, RandomGenerator); 41 | } 42 | 43 | /// 44 | /// Creates an instance of RFC4122 time based UUID generator, 45 | /// using the first IEEE 802 MAC address as node from available network workinterfaces on the machine. 46 | /// If none is available, a pseudo-random number generator is used. 47 | /// 48 | public TimeBasedGenerator() 49 | : this(GetIEEE802MACAddressBytes() ?? GetRandomBytes(6, RandomGenerator)) 50 | { 51 | } 52 | 53 | /// 54 | /// Generates RFC4122 time based UUID based on the provided. 55 | /// 56 | /// The DateTimeOffset to generate UUID on. 57 | /// 58 | public Guid GenerateGuid(DateTimeOffset dateTimeOffset) 59 | => GenerateGuid(dateTimeOffset, GetClockSequenceData(dateTimeOffset.ToUniversalTime().Ticks), _macAddressBytes); 60 | 61 | /// 62 | /// Generates RFC4122 time based UUID based on the provided. 63 | /// The is converted into UTC DateTimeOffset before use. 64 | /// 65 | /// The DateTime to generate UUID on. 66 | /// 67 | public Guid GenerateGuid(DateTime dateTime) 68 | => GenerateGuid(new DateTimeOffset(dateTime.ToUniversalTime(), TimeSpan.Zero)); 69 | 70 | /// 71 | /// Generates a RFC4122 time based UUID in the give . 72 | /// 73 | /// Use UUIDGenerationMode.FasterGeneration for faster UUID generation, without synchronizing the system clock. 74 | /// Use UUIDGenerationMode.WithUniquenessGuarantee to synchronize system clock. Later approach may be slower than the former one. 75 | /// 76 | public Guid GenerateGuid(GuidGenerationMode mode) 77 | { 78 | if (mode == GuidGenerationMode.FasterGeneration) 79 | { 80 | var clockSequenceData = ReadClockSequenceBytes(); 81 | return GenerateGuid(DateTimeOffset.UtcNow, clockSequenceData, _macAddressBytes); 82 | } 83 | 84 | var now = DateTimeOffset.UtcNow; 85 | if (now <= _lastClockSyncedAt) 86 | { 87 | lock (_mutex) 88 | { 89 | if (now <= _lastClockSyncedAt) 90 | { 91 | UpdateClockSequenceBytes(); 92 | _lastClockSyncedAt = now; 93 | } 94 | } 95 | } 96 | return GenerateGuid(now, ReadClockSequenceBytes(), _macAddressBytes); 97 | } 98 | 99 | /// 100 | /// Generates a RFC4122 time based UUID in UUIDGenerationMode.FasterGeneration mode. 101 | /// 102 | /// 103 | public Guid GenerateGuid() => GenerateGuid(GuidGenerationMode.FasterGeneration); 104 | 105 | private static Guid GenerateGuid(DateTimeOffset dateTime, byte[] clockSequenceData, byte[] macAddressBytes) 106 | { 107 | if(macAddressBytes == null) 108 | { 109 | throw new ArgumentNullException(nameof(macAddressBytes)); 110 | } 111 | 112 | if(macAddressBytes.Length != 6) 113 | { 114 | throw new ArgumentException($"{nameof(macAddressBytes)} must have 6 bytes."); 115 | } 116 | 117 | if(clockSequenceData == null) 118 | { 119 | throw new ArgumentNullException(nameof(clockSequenceData)); 120 | } 121 | 122 | if(clockSequenceData.Length != 2) 123 | { 124 | throw new ArgumentException($"{nameof(clockSequenceData)} must have 2 bytes."); 125 | } 126 | 127 | var ticksSinceStart = (dateTime - ClockStart).Ticks; 128 | var timestampBytes = BitConverter.GetBytes(ticksSinceStart); 129 | 130 | var data = new byte[16]; 131 | 132 | /* 133 | - Set the time_low field equal to the least significant 32 bits (bits zero through 31) of the timestamp in the same order of significance. 134 | - Set the time_mid field equal to bits 32 through 47 from the timestamp in the same order of significance. 135 | - Set the 12 least significant bits (bits zero through 11) of the time_hi_and_version field equal to bits 48 through 59 from the timestamp in the same order of significance. 136 | */ 137 | Array.Copy(timestampBytes, 0, data, 0, Math.Min(timestampBytes.Length, 8)); 138 | 139 | 140 | /* 141 | - Set the clock_seq_low field to the eight least significant bits (bits zero through 7) of the clock sequence in the same order of significance. 142 | - Set the 6 least significant bits (bits zero through 5) of the clock_seq_hi_and_reserved field to the 6 most significant bits (bits 8 through 13) of the clock sequence in the same order of significance. 143 | */ 144 | Array.Copy(clockSequenceData, 0, data, 8, clockSequenceData.Length); 145 | 146 | 147 | /* 148 | - Set the node field to the 48-bit IEEE address in the same order of significance as the address. 149 | */ 150 | Array.Copy(macAddressBytes, 0, data, 10, macAddressBytes.Length); 151 | 152 | 153 | data.AddVariantMarker().AddVersionMarker(UUIDVersion.TimeBased); 154 | 155 | return data.ToGuidFromActuallyOrderedBytes(); 156 | } 157 | 158 | private static byte[] GetClockSequenceData(long ticks) 159 | { 160 | var data = BitConverter.GetBytes(ticks); 161 | switch (data.Length) 162 | { 163 | case 0: return new byte[] { 0, 0 }; 164 | case 1: return new byte[] { 0, data[0] }; 165 | default: return new[] { data[0], data[1] }; 166 | } 167 | } 168 | 169 | private byte[] ReadClockSequenceBytes() 170 | { 171 | _rwLock.AcquireReaderLock(Timeout.Infinite); 172 | try 173 | { 174 | return new[] { _currentClockSequenceBytes[0], _currentClockSequenceBytes[1] }; 175 | } 176 | finally 177 | { 178 | _rwLock.ReleaseReaderLock(); 179 | } 180 | } 181 | 182 | private void UpdateClockSequenceBytes() 183 | { 184 | _rwLock.AcquireWriterLock(Timeout.Infinite); 185 | try 186 | { 187 | _currentClockSequenceBytes = GetRandomBytes(2, RandomGenerator); 188 | } 189 | finally 190 | { 191 | _rwLock.ReleaseWriterLock(); 192 | } 193 | } 194 | 195 | private static byte[] GetRandomBytes(int length, RandomNumberGenerator randomGenerator) 196 | { 197 | var data = new byte[length]; 198 | randomGenerator.GetBytes(data); 199 | return data; 200 | } 201 | 202 | // ReSharper disable once InconsistentNaming 203 | private static byte[]? GetIEEE802MACAddressBytes() 204 | { 205 | try 206 | { 207 | foreach (var @interface in NetworkInterface.GetAllNetworkInterfaces()) 208 | { 209 | if (@interface.NetworkInterfaceType == NetworkInterfaceType.Tunnel) 210 | { 211 | continue; 212 | } 213 | 214 | var physicalAddress = @interface.GetPhysicalAddress(); 215 | 216 | if (string.IsNullOrEmpty(physicalAddress.ToString())) 217 | { 218 | continue; 219 | } 220 | 221 | return physicalAddress.GetAddressBytes(); 222 | } 223 | } 224 | catch (Exception) 225 | { 226 | // ignored 227 | } 228 | 229 | return null; 230 | } 231 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/UUIDNameSpace.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | 9 | namespace Vlingo.Xoom.UUID; 10 | 11 | // ReSharper disable once InconsistentNaming 12 | public enum UUIDNameSpace 13 | { 14 | None = 0, 15 | Dns = 1, 16 | Url = 2, 17 | Oid = 3, 18 | X500 = 4 19 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/UUIDVersion.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved. 2 | // 3 | // This Source Code Form is subject to the terms of the 4 | // Mozilla Public License, v. 2.0. If a copy of the MPL 5 | // was not distributed with this file, You can obtain 6 | // one at https://mozilla.org/MPL/2.0/. 7 | 8 | namespace Vlingo.Xoom.UUID; 9 | 10 | // ReSharper disable once InconsistentNaming 11 | internal enum UUIDVersion 12 | { 13 | TimeBased = 0x10, 14 | NameBasedWithMd5 = 0x30, 15 | Random = 0x40, 16 | NamedBasedWithSha1 = 0x50 17 | } -------------------------------------------------------------------------------- /src/Vlingo.Xoom.UUID/Vlingo.Xoom.UUID.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | latest 6 | enable 7 | 8 | 9 | true 10 | $(VlingoVersion) 11 | Vlingo.Xoom.UUID 12 | Vlingo 13 | 14 | .NET implementation of UUID generation according to RFC4122 spec 15 | 16 | false 17 | LICENSE 18 | https://github.com/vlingo-net/xoom-net-uuid 19 | vlingo-64x64.png 20 | https://github.com/vlingo-net/xoom-net-uuid 21 | Debug;Release;Debug With Project References 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /vlingo-64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vlingo-net/xoom-net-uuid/1412bebb3e7c4f150bde194d1d316433d63c7f4a/vlingo-64x64.png --------------------------------------------------------------------------------