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;
1
unit WEID;
2
 
2
 
3
(*
3
(*
4
 * WEID<=>OID Converter for TurboPascal
4
 * WEID<=>OID Converter for TurboPascal
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 116... Line 129...
116
  actual_checksum: string;
129
  actual_checksum: string;
117
  expected_checksum: integer;
130
  expected_checksum: integer;
118
  complete: string;
131
  complete: string;
119
  oidstr: string;
132
  oidstr: string;
120
  arc: string;
133
  arc: string;
-
 
134
  domainpart: string;
-
 
135
  tmp: string;
121
begin
136
begin
122
  p := LastCharPos(weid,':');
137
  p := LastCharPos(weid,':');
123
  namespace := Copy(weid, 1, p);
138
  namespace := Copy(weid, 1, p);
124
  rest := Copy(weid, p+1, Length(weid)-p);
139
  rest := Copy(weid, p+1, Length(weid)-p);
125
 
140
 
126
  namespace := LowerCase(namespace); (* namespace is case insensitive *)
141
  namespace := LowerCase(namespace); (* namespace is case insensitive *)
-
 
142
 
-
 
143
  if Copy(namespace, 1, 5) = 'weid:' then
-
 
144
  begin
-
 
145
    tmp := Copy(namespace, 1, Length(namespace)-1);
-
 
146
    namespace[5] := '*'; (* to force searching the second ":" *)
-
 
147
    p := Pos(':', tmp);
-
 
148
    Delete(tmp, 1, p);
-
 
149
    if pos('.', tmp) > 0 then
-
 
150
    begin
-
 
151
      (* Spec Change 10: Class D / Domain-WEID *)
-
 
152
      if pos(':', tmp) > 0 then
-
 
153
      begin
-
 
154
        WeidToOid := '';
-
 
155
        exit;
-
 
156
      end;
-
 
157
      domainpart := '';
-
 
158
      while tmp <> '' do
-
 
159
      begin
-
 
160
        p := Pos('.', tmp);
-
 
161
        if p = 0 then
-
 
162
        begin
-
 
163
          domainpart := tmp + '-' + domainpart;
-
 
164
          break;
-
 
165
        end
-
 
166
        else
-
 
167
        begin
-
 
168
          domainpart := Copy(tmp, 1, p-1) + '-' + domainpart;
-
 
169
          Delete(tmp, 1, p);
-
 
170
        end;
-
 
171
      end;
-
 
172
      weid := 'weid:9-DNS-' + UpperCase(Domainpart) + Rest;
-
 
173
      WeidToOid := WeidToOid(weid);
-
 
174
      exit;
-
 
175
    end;
-
 
176
  end;
-
 
177
 
-
 
178
  if Copy(namespace, 1, 7) = 'weid:x-' then
-
 
179
  begin
-
 
180
    (* Spec Change 11: Proprietary Namespaces *)
-
 
181
    WeidToOid := '[Proprietary WEID Namespace]';
-
 
182
    Exit;
-
 
183
  end
127
  if namespace = 'weid:' then
184
  else if namespace = 'weid:' then  
128
  begin
185
  begin
129
    (* Class C *)
186
    (* Class C *)
130
    base := '1-3-6-1-4-1-SZ5-8';
187
    base := '1-3-6-1-4-1-SZ5-8';
131
  end
188
  end
132
  else if namespace = 'weid:pen:' then
189
  else if namespace = 'weid:pen:' then