Skip to content

Commit 7dcce32

Browse files
committed
apply suggestions from code review
1 parent bceecd0 commit 7dcce32

File tree

5 files changed

+99
-99
lines changed

5 files changed

+99
-99
lines changed

cli/compile/compile.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var (
5353
buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
5454
buildPath string // Path where to save compiled files.
5555
buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
56-
keysDir string // The path of the dir where to search for the custom keys to sign and encrypt a binary. Used only by the platforms that supports it
56+
keysPath string // The path of the dir where to search for the custom keys to sign and encrypt a binary. Used only by the platforms that supports it
5757
signKeyName string // The name of the custom signing key to use to sign a binary during the compile process. Used only by the platforms that supports it
5858
encryptKeyName string // The name of the custom encryption key to use to encrypt a binary during the compile process. Used only by the platforms that supports it
5959
warnings string // Used to tell gcc which warning level to use.
@@ -88,7 +88,7 @@ func NewCommand() *cobra.Command {
8888
" " + os.Args[0] + ` compile -b arduino:avr:uno --build-property "build.extra_flags=\"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n" +
8989
" " + os.Args[0] + ` compile -b arduino:avr:uno --build-property "build.extra_flags=-DPIN=2 \"-DMY_DEFINE=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n" +
9090
" " + os.Args[0] + ` compile -b arduino:avr:uno --build-property build.extra_flags=-DPIN=2 --build-property "compiler.cpp.extra_flags=\"-DSSID=\"hello world\"\"" /home/user/Arduino/MySketch` + "\n" +
91-
" " + os.Args[0] + ` compile -b arduino:mbed_portenta:envie_m7:security=sien --keys-input-dir /home/user/Arduino/keys --sign-key-name ecsdsa-p256-signing-key.pem --encrypt-key-name ecsdsa-p256-encrypt-key.pem /home/user/Arduino/MySketch` + "\n",
91+
" " + os.Args[0] + ` compile -b arduino:mbed_portenta:envie_m7:security=sien --keys-input-path /home/user/Arduino/keys --sign-key-name ecsdsa-p256-signing-key.pem --encrypt-key-name ecsdsa-p256-encrypt-key.pem /home/user/Arduino/MySketch` + "\n",
9292
Args: cobra.MaximumNArgs(1),
9393
Run: runCompileCommand,
9494
}
@@ -104,12 +104,12 @@ func NewCommand() *cobra.Command {
104104
tr("List of custom build properties separated by commas. Or can be used multiple times for multiple properties."))
105105
compileCommand.Flags().StringArrayVar(&buildProperties, "build-property", []string{},
106106
tr("Override a build property with a custom value. Can be used multiple times for multiple properties."))
107-
compileCommand.Flags().StringVar(&keysDir, "keys-input-dir", "",
108-
tr("The path of the dir where to search for the custom keys to sign and encrypt a binary. Used only by the platforms that supports it"))
107+
compileCommand.Flags().StringVar(&keysPath, "keys-input-path", "",
108+
tr("The path of the dir to search for the custom keys to sign and encrypt a binary. Used only by the platforms that support it"))
109109
compileCommand.Flags().StringVar(&signKeyName, "sign-key-name", "",
110-
tr("The name of the custom signing key to use to sign a binary during the compile process. Used only by the platforms that supports it"))
110+
tr("The name of the custom signing key to use to sign a binary during the compile process. Used only by the platforms that support it"))
111111
compileCommand.Flags().StringVar(&encryptKeyName, "encrypt-key-name", "",
112-
tr("The name of the custom encryption key to use to encrypt a binary during the compile process. Used only by the platforms that supports it"))
112+
tr("The name of the custom encryption key to use to encrypt a binary during the compile process. Used only by the platforms that support it"))
113113
compileCommand.Flags().StringVar(&warnings, "warnings", "none",
114114
tr(`Optional, can be: %s. Used to tell gcc which warning level to use (-W flag).`, "none, default, more, all"))
115115
compileCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Optional, turns on verbose mode."))
@@ -152,8 +152,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
152152

153153
sketchPath := arguments.InitSketchPath(path)
154154

155-
if keysDir != "" || signKeyName != "" || encryptKeyName != "" {
156-
arguments.CheckFlagsMandatory(cmd, "keys-input-dir", "sign-key-name", "encrypt-key-name")
155+
if keysPath != "" || signKeyName != "" || encryptKeyName != "" {
156+
arguments.CheckFlagsMandatory(cmd, "keys-input-path", "sign-key-name", "encrypt-key-name")
157157
}
158158

159159
var overrides map[string]string
@@ -212,9 +212,9 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
212212
CreateCompilationDatabaseOnly: compilationDatabaseOnly,
213213
SourceOverride: overrides,
214214
Library: library,
215-
Keysdir: keysDir,
216-
Signkeyname: signKeyName,
217-
Encryptkeyname: encryptKeyName,
215+
KeysPath: keysPath,
216+
SignKeyName: signKeyName,
217+
EncryptKeyName: encryptKeyName,
218218
}
219219
compileStdOut := new(bytes.Buffer)
220220
compileStdErr := new(bytes.Buffer)

commands/compile/compile.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,24 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
126126
}
127127

128128
// At the current time we do not have a way of knowing if a board supports the secure boot or not,
129-
// so, if the flags to override the default keys are used, we try override the corresponding property in the properties.txt nonetheless.
129+
// so, if the flags to override the default keys are used, we try override the corresponding platform property nonetheless.
130130
// It's not possible to use the default name for the keys since there could be more tools to sign and encrypt.
131131
// So it's mandatory to use all the tree flags to sign and encrypt the binary
132-
if req.Keysdir != "" && req.Signkeyname != "" && req.Encryptkeyname != "" {
133-
keysDirPath := paths.New(req.Keysdir)
132+
if req.KeysPath != "" && req.SignKeyName != "" && req.EncryptKeyName != "" {
133+
keysDirPath := paths.New(req.KeysPath)
134134
if !keysDirPath.IsDir() {
135135
return nil, &arduino.NotFoundError{Message: tr("The path specified is not a directory: %s", keysDirPath), Cause: err}
136136
}
137-
signKeyPath := keysDirPath.Join(req.GetSignkeyname())
137+
signKeyPath := keysDirPath.Join(req.GetSignKeyName())
138138
if !signKeyPath.Exist() {
139-
return nil, &arduino.NotFoundError{Message: tr("The path of the specified signing key do not exist: %s", signKeyPath), Cause: err}
139+
return nil, &arduino.NotFoundError{Message: tr("The path of the specified signing key does not exist: %s", signKeyPath), Cause: err}
140140
}
141-
encryptKeyPath := keysDirPath.Join(req.GetEncryptkeyname())
141+
encryptKeyPath := keysDirPath.Join(req.GetEncryptKeyName())
142142
if !encryptKeyPath.Exist() {
143-
return nil, &arduino.NotFoundError{Message: tr("The path of the specified encription key do not exist: %s", encryptKeyPath), Cause: err}
143+
return nil, &arduino.NotFoundError{Message: tr("The path of the specified encryption key does not exist: %s", encryptKeyPath), Cause: err}
144144
}
145145
InstalledPlatformRelease := pm.GetInstalledPlatformRelease(targetPlatform)
146-
ReplaceSecurityKeys(InstalledPlatformRelease.Properties, req.Keysdir, req.Signkeyname, req.Encryptkeyname)
146+
ReplaceSecurityKeys(InstalledPlatformRelease.Properties, req.KeysPath, req.SignKeyName, req.EncryptKeyName)
147147
}
148148

149149
builderCtx := &types.Context{}
@@ -319,17 +319,16 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
319319
}
320320

321321
// ReplaceSecurityKeys function will override the properties representing the security keys specified in the platform.txt file of a platform with the ones provided by the user.
322-
// The keys are stored in the keyDir
322+
// The keys are stored in the keyPath
323323
// signKeyName is the key used to sign a binary
324324
// encryptKeyName is the key used to encrypt it
325-
func ReplaceSecurityKeys(properties *properties.Map, keysDir, signKeyName, encryptKeyName string) {
325+
func ReplaceSecurityKeys(properties *properties.Map, keysPath, signKeyName, encryptKeyName string) {
326326
toolsProps := properties.SubTree("tools").FirstLevelOf()
327327
for toolName, toolProps := range toolsProps {
328-
// switch o else o select
329328
if toolProps.ContainsKey("keys.path") {
330329
key := "tools." + toolName + ".keys.path"
331-
properties.Set(key, keysDir)
332-
logrus.Tracef("Overriding Property: %s: %s", key, keysDir)
330+
properties.Set(key, keysPath)
331+
logrus.Tracef("Overriding Property: %s: %s", key, keysPath)
333332
}
334333
if toolProps.ContainsKey("sign.name") {
335334
key := "tools." + toolName + ".sign.name"

0 commit comments

Comments
 (0)