github.com/yogeshkumararora/slsa-github-generator@v1.10.1-0.20240520161934-11278bd5afb4/.github/actions/rng/action.yml (about) 1 # Copyright 2023 SLSA Authors 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 name: "RNG" 16 description: "Generate random bytes using /dev/urandom. WARNING: only use for non-cryptographic purposes (the results will show in logs)." 17 inputs: 18 length: 19 description: "Number of raw random bytes to generate." 20 default: 16 21 required: false 22 outputs: 23 random: 24 description: > 25 The output of the RNG encoded in hexadecimal. 26 Note: Due to the encoding, the length of the string will be twice as long as the input length requested by the user. 27 value: "${{ steps.rng.outputs.result }}" 28 29 runs: 30 using: "composite" 31 steps: 32 - name: Generate random 33 id: rng 34 shell: bash 35 env: 36 LENGTH: "${{ inputs.length }}" 37 run: | 38 set -euo pipefail 39 40 # Note: if we need to support different encoding, we can use 41 # `head -c"$LENGTH" /dev/urandom | xxd ...` instead. 42 # -l: the number of bytes 43 # -c: the number of bytes displayed per column 44 value=$(xxd -p -l "$LENGTH" -c "$LENGTH" /dev/urandom) 45 echo "result=$value" >> "$GITHUB_OUTPUT"