@@ -40,25 +40,30 @@ + (NSString*)uuid {
40
40
}
41
41
42
42
+ (NSString *)compactUuid {
43
- CFUUIDRef cfUUID = CFUUIDCreate (kCFAllocatorDefault ) ;
44
- CFUUIDBytes uuidBytes = CFUUIDGetUUIDBytes (cfUUID) ;
45
- CFRelease (cfUUID) ;
46
- NSData * data = [NSData dataWithBytes: (const void *)&uuidBytes
47
- length: 16 ] ;
48
- NSMutableString * s = [NSMutableString stringWithString: [data stringBase64Encoded ]] ;
49
-
50
- // Remove the padding at the end
51
- [s replaceOccurrencesOfString: @" ="
52
- withString: @" "
53
- options: 0
54
- range: NSMakeRange (0 , [s length ])] ;
55
-
56
- // Dashes are more readable than slashes
57
- [s replaceOccurrencesOfString: @" /"
58
- withString: @" -"
59
- options: 0
60
- range: NSMakeRange (0 , [s length ])] ;
61
- return [NSString stringWithString: s] ;
43
+ CFUUIDRef cfUUID = CFUUIDCreate (kCFAllocatorDefault ) ;
44
+ CFUUIDBytes uuidBytes = CFUUIDGetUUIDBytes (cfUUID) ;
45
+ CFRelease (cfUUID) ;
46
+ NSData * data = [NSData dataWithBytes: (const void *)&uuidBytes
47
+ length: 16 ] ;
48
+ NSMutableString * s = [NSMutableString stringWithString: [data stringBase64Encoded ]] ;
49
+
50
+ // Remove the padding at the end
51
+ [s replaceOccurrencesOfString: @" ="
52
+ withString: @" "
53
+ options: 0
54
+ range: NSMakeRange (0 , [s length ])] ;
55
+
56
+ // Change from standard Base64 to base64url (RFC4648) character set
57
+ [s replaceOccurrencesOfString: @" /"
58
+ withString: @" -"
59
+ options: 0
60
+ range: NSMakeRange (0 , [s length ])] ;
61
+ [s replaceOccurrencesOfString: @" +"
62
+ withString: @" _"
63
+ options: 0
64
+ range: NSMakeRange (0 , [s length ])] ;
65
+
66
+ return [NSString stringWithString: s] ;
62
67
}
63
68
64
69
@end
0 commit comments