Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 414692c

Browse files
committedJun 17, 2024
extract the redundant code into method
1 parent d95ce24 commit 414692c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎credentials/generate-revocation-set.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ def extract_single_integer_attribute(subject, oid):
6464
return None
6565

6666

67+
def extract_single_attribute_from_cn(cn, marker):
68+
val_len = 4
69+
start_idx = cn.find(marker)
70+
71+
if start_idx != -1:
72+
val_start_idx = start_idx + len(marker)
73+
return int(cn[val_start_idx:val_start_idx + val_len], 16)
74+
75+
return None
76+
77+
6778
def parse_vid_pid_from_distinguished_name(distinguished_name):
6879
# VID/PID encoded using Matter specific RDNs
6980
vid = extract_single_integer_attribute(distinguished_name, OID_VENDOR_ID)
@@ -72,14 +83,8 @@ def parse_vid_pid_from_distinguished_name(distinguished_name):
7283
# Fallback method to get the VID/PID, encoded in CN as "Mvid:FFFF Mpid:1234"
7384
if vid is None and pid is None:
7485
cn = distinguished_name.get_attributes_for_oid(x509.ObjectIdentifier("2.5.4.3"))[0].value
75-
76-
vid_start = cn.find('Mvid:')
77-
if vid_start != -1:
78-
vid = int(cn[vid_start + 5:vid_start + 9], 16)
79-
80-
pid_start = cn.find('Mpid:')
81-
if pid_start != -1:
82-
pid = int(cn[pid_start + 5:pid_start + 9], 16)
86+
vid = extract_single_attribute_from_cn(cn, 'Mvid:')
87+
pid = extract_single_attribute_from_cn(cn, 'Mpid:')
8388

8489
return vid, pid
8590

0 commit comments

Comments
 (0)
Please sign in to comment.