Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add keys generate command #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
umbynos wants to merge 5 commits into master from umbynos/keys_generate_command
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Apply suggestions from code review
Co-authored-by: per1234 <accounts@perglass.com>
  • Loading branch information
umbynos and per1234 committed Mar 25, 2022
commit 0ff01b7553abc8dfbad3eea5d091ac0f9f00e41a
2 changes: 1 addition & 1 deletion arduino/errors.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func (e *TempDirCreationFailedError) ToRPCStatus() *status.Status {
return status.New(codes.Unavailable, e.Error())
}

// FileCreationFailedError is returned if a temp file could not be created
// FileCreationFailedError is returned if a file could not be created
type FileCreationFailedError struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is an exported object, this will be a breaking change and so the standard procedure should be followed to communicate that to the users.

umbynos reacted with thumbs up emoji
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not though about it, but you are right

Message string
Cause error
Expand Down
2 changes: 1 addition & 1 deletion cli/keys/generate.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func runGenerateCommand(command *cobra.Command, args []string) {
KeysKeychain: keysKeychain,
})
if err != nil {
feedback.Errorf(tr("Error during Generate: %v"), err)
feedback.Errorf(tr("Error during generate: %v"), err)
os.Exit(errorcodes.ErrGeneric)
}
feedback.PrintResult(result{resp})
Expand Down
15 changes: 9 additions & 6 deletions commands/keys/generate.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ func genEcdsaP256() ([]byte, []byte, error) {
}

// genCFile will take a file as input, the byte slice that represents the key and the type of the key.
// If will then write the file and report an error if one is found
// It will then write the file and report an error if one is found
func genCFile(file *os.File, bytes []byte, t string) (err error) {
fileContent := fmt.Sprintf(`/* Autogenerated, do not edit */
const unsigned char rsa_%s_key[] = {
%s
// clang-format off
%s
// clang-format on
};
const unsigned int ec_%s_key_len = %d;
`, t, formatCData(bytes), t, len(bytes))
Expand All @@ -210,16 +212,17 @@ const unsigned int ec_%s_key_len = %d;
// taken and adapted from https://git.furworks.de/Zephyr/mcuboot/src/commit/3869e760901a27adff47ccaea803a42f1b0169c0/imgtool/imgtool.go#L313
func formatCData(data []byte) string {
buf := new(bytes.Buffer)
indText := strings.Repeat("\t", 1)
indText := strings.Repeat("", 2)
for i, b := range data {
if i%8 == 0 {
if i > 0 {
fmt.Fprintf(buf, "\n%s", indText)
}
fmt.Fprintf(buf, indText)
} else {
fmt.Fprintf(buf, " ")
}
fmt.Fprintf(buf, "0x%02x,", b)
if i%8 == 7 {
fmt.Fprintf(buf, "\n")
}
}
return buf.String()
}
4 changes: 2 additions & 2 deletions test/test_keys.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_keys_generate(run_command, working_dir):
# Overwrite security keys
result = run_command(["keys", "generate", "--key-name", sign_key_name])
assert result.failed
assert f"Error during Generate: Cannot create file: File already exists: {working_dir}" in result.stderr
assert f"Error during generate: Cannot create file: File already exists: {working_dir}" in result.stderr

# Create security keys in specified directory
keychain_name = "keychain"
Expand Down Expand Up @@ -64,4 +64,4 @@ def test_keys_generate(run_command, working_dir):
["keys", "generate", "--key-name", sign_key_name, "--keys-keychain", keychain_path, "-t", "rsa"]
)
assert result.failed
assert "Error during Generate: Cannot create file: Unsupported algorithm: rsa" in result.stderr
assert "Error during generate: Cannot create file: Unsupported algorithm: rsa" in result.stderr

AltStyle によって変換されたページ (->オリジナル) /