Subversion Repositories oidplus

Rev

Rev 750 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 750 Rev 1377
Line 1... Line 1...
1
unit WEID_Delphi;
1
unit WEID_Delphi;
2
 
2
 
3
(*
3
(*
4
 * WEID<=>OID Converter for Delphi
4
 * WEID<=>OID Converter for Delphi
5
 * (c) Webfan.de, ViaThinkSoft
5
 * (c) Webfan.de, ViaThinkSoft
6
 * Revision 2022-02-22
6
 * Revision 2023-08-10
7
 *)
7
 *)
8
 
8
 
9
(*
9
(*
10
  What is a WEID?
10
 * What is a WEID?
11
    A WEID (WEhowski IDentifier) is an alternative representation of an
11
 *     A WEID (WEhowski IDentifier) is an alternative representation of an
12
     OID (Object IDentifier) defined by Till Wehowski.
12
 *     OID (Object IDentifier) defined by Till Wehowski.
13
     In OIDs, arcs are in decimal base 10. In WEIDs, the arcs are in base 36.
13
 *     In OIDs, arcs are in decimal base 10. In WEIDs, the arcs are in base 36.
14
     Also, each WEID has a check digit at the end (called WeLohn Check Digit).
14
 *     Also, each WEID has a check digit at the end (called WeLuhn Check Digit).
15
 
15
 *
16
  Changes in the December 2021 definition by Daniel Marschall:
16
 * The full specification can be found here: https://weid.info/spec.html
-
 
17
 *
-
 
18
 * This converter supports WEID as of Spec Change #11
-
 
19
 *
-
 
20
 * A few short notes:
17
     - There are several classes of WEIDs which have different OID bases:
21
 *     - There are several classes of WEIDs which have different OID bases:
18
           "Class C" WEID:  weid:EXAMPLE-3      (base .1.3.6.1.4.1.37553.8.)
22
 *           "Class A" WEID:  weid:root:2-RR-?
-
 
23
 *                            oid:2.999
19
                            oid:1.3.6.1.4.1.37553.8.32488192274
24
 *                            WEID class base OID: (OID Root)
20
           "Class B" WEID:  weid:pen:SX0-7PR-6  (base .1.3.6.1.4.1.)
25
 *           "Class B" WEID:  weid:pen:SX0-7PR-?
21
                            oid:1.3.6.1.4.1.37476.9999
26
 *                            oid:1.3.6.1.4.1.37476.9999
-
 
27
 *                            WEID class base OID: 1.3.6.1.4.1
22
           "Class A" WEID:  weid:root:2-RR-2    (base .)
28
 *           "Class C" WEID:  weid:EXAMPLE-?
23
                            oid:2.999
29
 *                            oid:1.3.6.1.4.1.37553.8.32488192274
-
 
30
 *                            WEID class base OID: 1.3.6.1.4.1.37553.8
-
 
31
 *           "Class D" WEID:  weid:example.com:TEST-? is equal to weid:9-DNS-COM-EXAMPLE-TEST-?
-
 
32
 *                            Since the check digit is based on the OID, the check digit is equal for both notations.
-
 
33
 *                            oid:1.3.6.1.4.1.37553.8.9.17704.32488192274.16438.1372205
-
 
34
 *                            WEID class base OID: 1.3.6.1.4.1.37553.8.9.17704
-
 
35
 *     - The last arc in a WEID is the check digit. A question mark is the wildcard for an unknown check digit.
-
 
36
 *       In this case, the converter will return the correct expected check digit for the input.
24
     - The namespace (weid:, weid:pen:, weid:root:) is now case insensitive.
37
 *     - The namespace (weid:, weid:pen:, weid:root:) is case insensitive.
25
     - Padding with '0' characters is valid (e.g. weid:000EXAMPLE-3)
38
 *     - Padding with '0' characters is valid (e.g. weid:000EXAMPLE-3)
26
       The paddings do not count into the WeLuhn check-digit.
39
 *       The paddings do not count into the WeLuhn check digit.
27
*)
40
 *)
28
 
41
 
29
interface
42
interface
30
 
43
 
31
(*
44
(*
Line 193... Line 206...
193
  actual_checksum: string;
206
  actual_checksum: string;
194
  expected_checksum: integer;
207
  expected_checksum: integer;
195
  complete: string;
208
  complete: string;
196
  oidstr: string;
209
  oidstr: string;
197
  arc: string;
210
  arc: string;
-
 
211
  domainpart: string;
-
 
212
  tmp: string;
198
begin
213
begin
199
  p := LastCharPos(weid,':');
214
  p := LastCharPos(weid,':');
200
  namespace := Copy(weid, 1, p);
215
  namespace := Copy(weid, 1, p);
201
  rest := Copy(weid, p+1, Length(weid)-p);
216
  rest := Copy(weid, p+1, Length(weid)-p);
202
 
217
 
203
  namespace := LowerCase(namespace); (* namespace is case insensitive *)
218
  namespace := LowerCase(namespace); (* namespace is case insensitive *)
-
 
219
 
-
 
220
  if Copy(namespace, 1, 5) = 'weid:' then
-
 
221
  begin
-
 
222
    tmp := Copy(namespace, 1, Length(namespace)-1);
-
 
223
    p := Pos(':', tmp, 5);
-
 
224
    Delete(tmp, 1, p);
-
 
225
    if pos('.', tmp) > 0 then
-
 
226
    begin
-
 
227
      (* Spec Change 10: Class D / Domain-WEID *)
-
 
228
      if pos(':', tmp) > 0 then
-
 
229
      begin
-
 
230
        result := '';
-
 
231
        exit;
-
 
232
      end;
-
 
233
      domainpart := '';
-
 
234
      while tmp <> '' do
-
 
235
      begin
-
 
236
        p := Pos('.', tmp);
-
 
237
        if p = 0 then
-
 
238
        begin
-
 
239
          domainpart := tmp + '-' + domainpart;
-
 
240
          break;
-
 
241
        end
-
 
242
        else
-
 
243
        begin
-
 
244
          domainpart := Copy(tmp, 1, p-1) + '-' + domainpart;
-
 
245
          Delete(tmp, 1, p);
-
 
246
        end;
-
 
247
      end;
-
 
248
      weid := 'weid:9-DNS-' + UpperCase(Domainpart) + Rest;
-
 
249
      result := WeidToOid(weid);
-
 
250
      exit;
-
 
251
    end;
-
 
252
  end;
-
 
253
 
-
 
254
  if Copy(namespace, 1, 7) = 'weid:x-' then
-
 
255
  begin
-
 
256
        (* Spec Change 11: Proprietary Namespaces *)
-
 
257
    result := '[Proprietary WEID Namespace]';
-
 
258
    Exit;
-
 
259
  end
204
  if namespace = 'weid:' then
260
  else if namespace = 'weid:' then
205
  begin
261
  begin
206
    (* Class C *)
262
    (* Class C *)
207
    base := '1-3-6-1-4-1-SZ5-8';
263
    base := '1-3-6-1-4-1-SZ5-8';
208
  end
264
  end
209
  else if namespace = 'weid:pen:' then
265
  else if namespace = 'weid:pen:' then