Skip to content

Get-SodiumPublicKey -AsByteArray does not preserve a single pipeline object #76

Description

Problem

The Get-SodiumPublicKey function has a [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', ...)] attribute with the justification: "The unary comma preserves the byte array as one pipeline object."

However, the unary comma does not prevent ForEach-Object (or similar pipeline consumers) from enumerating the byte array. Piping the output enumerates it into 32 individual bytes:

$kp = New-SodiumKeyPair
$piped = Get-SodiumPublicKey -PrivateKey $kp.PrivateKey -AsByteArray | ForEach-Object { $_ }
$piped.Count # 32

This makes the justification misleading and the suppression potentially unnecessary.

Suggested fix

Either:

  1. Remove the misleading SuppressMessageAttribute justification and let the byte array enumerate naturally (current actual behavior), or
  2. Actually preserve the byte array as a single pipeline object, e.g. by wrapping it with Write-Output -NoEnumerate or PSObject.AsPSObject(...).

Related code

  • src/functions/public/Get-SodiumPublicKey.ps1

Notes

Direct assignment already returns a [byte[]], so the -AsByteArray switch is useful for assignment scenarios. The issue is specifically the documented/pipeline-preservation claim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions