Skip to content

Conversation

@oncilla
Copy link
Contributor

@oncilla oncilla commented Jul 9, 2025

The scion-pki CLI commands now support reading from stdin when the file path is set to -, where appropriate. This allows the user to pipe data directly into the command without the need to create temporary files.

Furthermore, the scion-pki trc extract certificates command has two additional filtering options: --type and --subject.isd-as, allowing the user to filter the extracted certificates.

@oncilla oncilla requested review from katyatitkova and romshark July 9, 2025 11:48

// ReadFileOrStdin reads the content of a file or stdin if the path is "-".
// It returns the content as a byte slice.
func ReadFileOrStdin(path string) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open for suggestions if there is a more suitable place to put this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's fine to keep it here.

Maybe worth adding:

// ReadFileOrStdin reads the content of a file or stdin if the path is "-".
// It returns the content as a byte slice.
// Follows UNIX utility syntax guidelines.
// See https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02

types[typ] = true
}

ias := make(map[addr.IA]bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ias := make(map[addr.IA]bool)
ias := make(map[addr.IA]bool, len(flags.ias))

Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := runExtractCertificates(args[0], flags.out); err != nil {
types := make(map[cppki.CertType]bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sets can be used for types and ias (like map[cppki.CertType]struct{}) to reduce the ambiguity a bit.

The checks can then just be like:

if len(ias) > 0 && !ias[ia] {
	continue
}

if err != nil {
return fmt.Errorf("invalid certificate %s: %w", cert.Subject.CommonName, err)
}
if len(types) > 0 && !types[typ] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if types contains typ then len(types) cannot be 0, right? Hence len(types) > 0 looks pointless to me, am I missing something?

Copy link
Contributor

@romshark romshark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some nitpicks.

I fixed the linter errors. I hope you don't mind the line breaking style.

oncilla and others added 2 commits December 19, 2025 16:15
The `scion-pki` CLI commands now support reading from stdin
when the file path is set to `-`, where appropriate. This allows
the user to pipe data directly into the command without
the need to create temporary files.

Furthermore, the `scion-pki trc extract certificates` command has two
additional filtering options: `--type` and `--subject.isd-as`, allowing
the user to filter the extracted certificates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants