From d477a8a939f6fd783d7dcb2399b38c7372e8fbc7 Mon Sep 17 00:00:00 2001 From: nishiki Date: Wed, 19 Mar 2014 20:50:12 +0100 Subject: [PATCH] check if we have the public share key --- MPW/Config.rb | 10 ++++++++-- i18n/cli/en.yml | 2 ++ i18n/cli/fr.yml | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/MPW/Config.rb b/MPW/Config.rb index fadfbff..c2c7d8d 100644 --- a/MPW/Config.rb +++ b/MPW/Config.rb @@ -66,6 +66,11 @@ module MPW @error_msg = I18n.t('error.config.key_bad_format') return false end + + if !check_gpg_key?(k, false) + @error_msg = I18n.t('error.config.no_key_public', :key => k) + return false + end end end @@ -166,10 +171,11 @@ module MPW end # Check if private key exist + # @args: only_private -> search only private key # @rtrn: true if the key exist, else false - def check_gpg_key? + def check_gpg_key?(key = @key, only_private = true) ctx = GPGME::Ctx.new - ctx.each_key(@key, true) do |key| + ctx.each_key(key, only_private) do return true end diff --git a/i18n/cli/en.yml b/i18n/cli/en.yml index 61df851..1d29686 100644 --- a/i18n/cli/en.yml +++ b/i18n/cli/en.yml @@ -5,6 +5,7 @@ en: write: "Can't write the config file!" check: "Checkconfig failed!" key_bad_format: "The key string isn't in good format!" + no_key_public: "You haven't the public key of %{key}!" genkey_gpg: exception: "Can't create the GPG key!" name: "You must define a name for your GPG key!" @@ -90,6 +91,7 @@ en: length: "Size of the GPG key [default=2048]: " expire: "Expire time of the GPG key [default=0 (unlimited)]: " wait: "Please waiting during the GPG key generate, this process can take few minutes." + valid: "Your GPG key has been created ;-)" update: title: "Update an item" name: "Enter the name [%{name}]: " diff --git a/i18n/cli/fr.yml b/i18n/cli/fr.yml index cc2a982..1ea2e57 100644 --- a/i18n/cli/fr.yml +++ b/i18n/cli/fr.yml @@ -5,6 +5,7 @@ fr: write: "Impossible d'écrire le fichier de configuration!" check: "Le fichier de configuration est invalide!" key_bad_format: "La clé GPG est invalide!" + no_key_public: "Vous ne possédez pas la clé publique de %{key}!" genkey_gpg: exception: "La création de la clé GPG n'a pas pu aboutir!" name: "Vous devez définir un nom pour votre clé GPG!" @@ -90,6 +91,7 @@ fr: length: "Taille de la clé GPG [défaut=2048]: " expire: "Expiration de la clé GPG [défaut=0 (illimité)]: " wait: "Veuillez patienter durant la génération de votre clé GPG, ce processus peut prendre quelques minutes." + valid: "Votre clé GPG a bien été créée ;-)" update: title: "Mis à jour d'un élément" name: "Entrez le nom [%{name}]: "