-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from "./print-userfn"; | ||
export * as lvstlv from "./tlv"; | ||
export * from "./translate"; | ||
export { LvsModel } from "./tlv"; | ||
export { toPolicy, type UserFn, type Vtable, type VtableInput } from "./translate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { TrustSchemaPolicy } from "@ndn/trust-schema"; | ||
import { assert } from "@ndn/util"; | ||
|
||
import { neededFnsMap } from "./translate"; | ||
|
||
/** | ||
* Print user functions as ECMAScript module. | ||
* @param policy - Policy generated by {@link toPolicy}. | ||
* | ||
* @throws Error | ||
* Policy is not generated by {@link toPolicy}. | ||
*/ | ||
export function printUserFns(policy: TrustSchemaPolicy): string { | ||
const neededFns = neededFnsMap.get(policy); | ||
assert(neededFns, "policy is not translated by toPolicy"); | ||
|
||
const lines: string[] = [ | ||
"import { assert } from \"@ndn/util\";", | ||
"/** @typedef {import(\"@ndn/packet\").Component} Component */", | ||
]; | ||
for (const [fn, nargSet] of neededFns) { | ||
lines.push( | ||
"", | ||
"/**", | ||
` * LVS user function ${fn}.`, | ||
" * @param {Component} value", | ||
" * @param {ReadonlyArray<Component>} args", | ||
" * @returns {boolean}", | ||
" */", | ||
`export function ${fn}(value, args) {`, | ||
` assert([${Array.from(nargSet).toSorted((a, b) => a - b).join(", ")}].includes(args.length));`, | ||
" // TODO", | ||
" return false;", | ||
"}", | ||
); | ||
} | ||
return lines.join("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// https://github.com/named-data/python-ndn/blob/96ae4bfb0060435e3f19c11d37feca512a8bd1f5/docs/src/lvs/lvs.rst#tutorial | ||
|
||
// The platform prefix definition. The pair of quotes means that it can only be matched by the identical component. | ||
#platform: "ndn"/"blog" | ||
// The certificate name suffix definition. Each underscore can be matched by an arbitrary pattern except that contains slash. | ||
#KEY: "KEY"/_/_/_ | ||
// The root certificate definition, i.e., /ndn/blog/KEY/<key-id>/<issuer>/<cert-id>. | ||
#root: #platform/#KEY | ||
// Admin's certificate definition. The non-sharp patterns, role and adminID, are sent from the application. Each pattern can match an arbitrary components, but the matched components for the same pattern should be the same. The constraint shows that the component "_role" must be "admin". The underscore means that the matched components for the pattern "_role" may not be identical in the chain. The admin's certificate must be signed by the root certificate. | ||
#admin: #platform/_role/adminID/#KEY & {_role: "admin"} <= #root | ||
// author's certificate definition. The ID is verified by a user function. Both constraints must be met. It can only be signed by the admin's certificate. | ||
#author: #platform/_role/ID/#KEY & {_role: "author", ID: $isValidID()} <= #admin | ||
// author's and reader's certificate definition. The role can be either "reader" or "author". The ID is verified by a user function. Both constraints must be met. It can only be signed by the admin's certificate. | ||
#user: #platform/_role/ID/#KEY & {_role: "reader"|"author", ID: $isValidID()} <= #admin | ||
// article's trust schema. The component "year" is verified by a user function. The article can be signed by the admin's certificate or one author's certificate. | ||
#article: #platform/ID/"post"/year/articleID & {year: $isValidYear()} <= #admin | #author |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters