Skip to content

Commit

Permalink
mdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Nov 21, 2024
1 parent d16dbb6 commit f05b502
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
39 changes: 30 additions & 9 deletions lib/eudi/mdoc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ defmodule CA.MDoc do
version = :maps.get("version", map, [])
validityInfo = :maps.get("validityInfo", map, [])
valueDigests = :maps.get("valueDigests", map, [])
[{_,nameSpacesList}] = :maps.to_list(valueDigests)
[
docType: docType,
digestAlgorithm: da,
deviceKeyInfo: dki,
validityInfo: validityInfo,
status: status,
valueDigests: valueDigests,
valueDigests: :lists.map(fn x -> parseTag(x) end, nameSpacesList),
version: version,
]
end
Expand All @@ -56,13 +57,17 @@ defmodule CA.MDoc do
end

def parseTag(%{33 => %CBOR.Tag{tag: type, value: value}}) when is_binary(value) do
{:ok, cbor, _} = decode(value)
[tag: {33,type}, value: :base64.encode(value)]
end

def parseTag(%{33 => tags}) when is_list(tags) do
:lists.map(fn %CBOR.Tag{tag: type, value: value} ->
[tag: {33,type}, value: :base64.encode(value)]
end, tags)
end

def parseTag(%{33 => %CBOR.Tag{tag: type, value: value}}) do
{:ok, cbor, _} = decode(value)
[tag: {33,type}, value: cbor]
[tag: {33,type}, value: :base64.encode(value)]
end

def parseTag(%CBOR.Tag{tag: :bytes, value: bytes}) when is_binary(bytes) do
Expand All @@ -71,11 +76,12 @@ defmodule CA.MDoc do
{:ok, cbor, _} -> [tag: :bytes, decoded: true, value: parseTag(cbor)]
end
rescue _ ->
[tag: :bytes, value: :base64.encode(bytes)]
[tag: :bytes, value: :base64.encode(bytes), raw: true]
end
end

def parseTag(%CBOR.Tag{tag: :simple, value: bytes}) when is_binary(bytes) do
{:ok, cbor, _} = decode(bytes)

Check warning on line 84 in lib/eudi/mdoc.ex

View workflow job for this annotation

GitHub Actions / build

variable "cbor" is unused (if the variable is not meant to be used, prefix it with an underscore)
[tag: :simple, value: :base64.encode(bytes)]
end

Expand All @@ -101,14 +107,29 @@ defmodule CA.MDoc do

def parseTag(value) do value end

def parseMDoc(%{"deviceAuth"=> %{"deviceSignature" => tags}, "nameSpaces"=> ns}) do
[
deviceAuth: [deviceSignature: :lists.map(fn x -> parseTag(x) end, tags)],
nameSpaces: :lists.map(fn x -> parseTag(x) end, :lists.flatten([ns])),
]
end

def parseMDoc(%{"issuerAuth"=> [f,s|issuerAuth], "nameSpaces"=> nameSpaces}) do
[{name,nameSpacesList}] = :maps.to_list(nameSpaces)
[{name,ns}] = :maps.to_list(nameSpaces)
[
ns: name,
header: parseTag(f),
certificate: parseTag(s),
certificates: parseTag(s),
issuerAuth: :lists.map(fn x -> parseTag(x) end, issuerAuth),
nameSpaces: :lists.map(fn x -> parseTag(x) end, nameSpacesList),
nameSpaces: :lists.map(fn x -> parseTag(x) end, :lists.flatten([ns])),
docType: name,
]
end

def parseMDoc(%{"issuerSigned"=> issuerSigned, "deviceSigned"=> deviceSigned, "docType" => docType}) do
[
issuerSigned: parseMDoc(issuerSigned),
deviceSigned: parseMDoc(deviceSigned),
docType: docType
]
end

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/mdoc/pid.b64u
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
omppc3N1ZXJBdXRohEOhASahGCFZAugwggLkMIICaqADAgECAhRyMm32Ywiae1APjD8mpoXLwsLSyjAKBggqhkjOPQQDAjBcMR4wHAYDVQQDDBVQSUQgSXNzdWVyIENBIC0gVVQgMDExLTArBgNVBAoMJEVVREkgV2FsbGV0IFJlZmVyZW5jZSBJbXBsZW1lbnRhdGlvbjELMAkGA1UEBhMCVVQwHhcNMjMwOTAyMTc0MjUxWhcNMjQxMTI1MTc0MjUwWjBUMRYwFAYDVQQDDA1QSUQgRFMgLSAwMDAxMS0wKwYDVQQKDCRFVURJIFdhbGxldCBSZWZlcmVuY2UgSW1wbGVtZW50YXRpb24xCzAJB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