Check-in [9472f708c9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a function for generating a random (v4) UUID and a test command using it.
Timelines: family | ancestors | descendants | both | gen-uuid
Files: files | file ages | folders
SHA3-256: 9472f708c99b4325bf4654b04f8c9a7abc08394277d921d02e3522deef2d5029
User & Date: danield 2025-07-07 15:11:23.058
Context
2025-07-30
17:14
Add the test-generate-uuid command. check-in: 062bb67c03 user: danield tags: trunk
2025-07-07
15:16
PoC for the previous check-in: use UUIDs for project-code and server-code. check-in: e38c068029 user: danield tags: gen-uuid
15:11
Add a function for generating a random (v4) UUID and a test command using it. check-in: 9472f708c9 user: danield tags: gen-uuid
2025-07-05
11:35
On the 'user capabilities changed' notification, correct /setup_uedit?uid=... to /setup_uedit?id=... check-in: c786b19094 user: stephan tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/util.c.
897
898
899
900
901
902
903










































904
905
906
907
908
909
910
    fossil_print("%s (%d bits of entropy)\n", zPassword,
                 (int)(log(et)/log(2.0)));
  }else{
    fossil_print("%s\n", zPassword);
  }
  fossil_free(zPassword);
}











































/*
** Return the number of decimal digits in a nonnegative integer.  This is useful
** when formatting text.
*/
int fossil_num_digits(int n){
  return n<      10 ? 1 : n<      100 ? 2 : n<      1000 ? 3







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
    fossil_print("%s (%d bits of entropy)\n", zPassword,
                 (int)(log(et)/log(2.0)));
  }else{
    fossil_print("%s\n", zPassword);
  }
  fossil_free(zPassword);
}

/*
** Generate a version 4 ("random"), variant 1 UUID (RFC 9562, Section 5.4).
**
** Format: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
**           where  M=4  and  N=8, 9, a, or b    (this leaves 122 random bits)
*/
char* fossil_generate_uuid() {
  static const char zDigits[] = "0123456789abcdef";
  unsigned char aBlob[16];
  unsigned char zStr[37];
  unsigned char *p = zStr;
  int i, k;

  sqlite3_randomness(16, aBlob);
  aBlob[6] = (aBlob[6]&0x0f) + 0x40; /* Version byte:  0100 xxxx */
  aBlob[8] = (aBlob[8]&0x3f) + 0x80; /* Variant byte:  1000 xxxx */

  for(i=0, k=0x550; i<16; i++, k=k>>1){
    if( k&1 ){
      *p++ = '-';                    /* Add a dash after byte 4, 6, 8, and 12 */
    }
    *p++ = zDigits[aBlob[i]>>4];
    *p++ = zDigits[aBlob[i]&0xf];
  }
  *p = 0;

  return mprintf("%s", zStr);
}

/*
** COMMAND: test-generate-uuid
**
** Usage: %fossil test-generate-uuid
**
** Generate a version 4 ("random"), variant 1 UUID (RFC 9562, Section 5.4):
**
**     xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx  - where  M=4  and  N=8, 9, a, or b
*/
void test_generate_uuid(void){
  fossil_print("%s\n", fossil_generate_uuid());
}

/*
** Return the number of decimal digits in a nonnegative integer.  This is useful
** when formatting text.
*/
int fossil_num_digits(int n){
  return n<      10 ? 1 : n<      100 ? 2 : n<      1000 ? 3