FIRCLSUUID.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "Crashlytics/Shared/FIRCLSUUID.h"
  15. #import "Crashlytics/Shared/FIRCLSByteUtility.h"
  16. /// Use an enum to define a true compile-time integer constant. This prevents
  17. /// warning below where the constant is used to declare the size of an array.
  18. enum {
  19. /// The buffer size needed to hold the hexadecimal string representation of a
  20. /// 16-byte UUID. This accounts for 32 characters (2 for each byte) plus one
  21. /// byte for the null terminator.
  22. FIRCLSUUIDStringLength = (16 * 2) + 1
  23. };
  24. #pragma mark Public methods
  25. NSString *FIRCLSGenerateUUID(void) {
  26. NSString *string;
  27. CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
  28. string = CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, uuid));
  29. CFRelease(uuid);
  30. return string;
  31. }
  32. NSString *FIRCLSUUIDToNSString(const uint8_t *uuid) {
  33. char uuidString[FIRCLSUUIDStringLength];
  34. FIRCLSSafeHexToString(uuid, 16, uuidString);
  35. return [NSString stringWithUTF8String:uuidString];
  36. }