Skip to content

Commit

Permalink
Fix V5 UUID inconsistencies when using UTF-8 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
vjamrich authored and daegalus committed Mar 29, 2024
1 parent 617b1ff commit 2fcde83
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/v5.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:uuid/data.dart';

import 'dart:convert';
import 'enums.dart';
import 'parsing.dart';
import 'v4.dart';
Expand Down Expand Up @@ -47,11 +48,8 @@ class UuidV5 {
// Convert namespace UUID to Byte List
var bytes = UuidParsing.parse(namespace);

// Convert name to a list of bytes
var nameBytes = <int>[];
for (var singleChar in name.codeUnits) {
nameBytes.add(singleChar);
}
// Convert name to UTF-8 bytes
var nameBytes = utf8.encode(name);

// Generate SHA1 using namespace concatenated with name
var hashBytes = crypto.sha1.convert([...bytes, ...nameBytes]).bytes;
Expand Down

0 comments on commit 2fcde83

Please sign in to comment.