Index: tools/hmac-main.adb ================================================================== --- tools/hmac-main.adb +++ tools/hmac-main.adb @@ -21,10 +21,11 @@ with Ada.Text_IO.Text_Streams; with Natools.Getopt_Long; with Natools.S_Expressions; with Natools.S_Expressions.Encodings; +with Natools.S_Expressions.File_Readers; procedure HMAC.Main is procedure Base64_Output (Digest : in Ada.Streams.Stream_Element_Array); -- Output the given binary Digest in base-64 @@ -40,10 +41,11 @@ package Options is type Id is (Base64_Output, + Key_File, Lower_Hex_Output, Raw_Output, Upper_Hex_Output); end Options; @@ -70,17 +72,26 @@ overriding procedure Option (Handler : in out Callback; Id : in Options.Id; - Argument : in String) - is - pragma Unreferenced (Argument); + Argument : in String) is begin case Id is when Options.Base64_Output => Handler.Output := Base64_Output'Access; + when Options.Key_File => + if Argument = "-" then + Handler.Key := Ada.Strings.Unbounded.To_Unbounded_String + (Ada.Text_IO.Get_Line); + else + Handler.Key := Ada.Strings.Unbounded.To_Unbounded_String + (Natools.S_Expressions.To_String + (Natools.S_Expressions.File_Readers.Reader + (Argument).Read)); + end if; + Handler.Has_Key := True; when Options.Lower_Hex_Output => Handler.Output := Lower_Hex_Output'Access; when Options.Raw_Output => Handler.Output := Raw_Output'Access; when Options.Upper_Hex_Output => @@ -134,10 +145,12 @@ Opt_Config : Getopt.Configuration; Handler : Callback; begin Opt_Config.Add_Option ("base64", 'b', Getopt.No_Argument, Options.Base64_Output); + Opt_Config.Add_Option + ("key-file", 'f', Getopt.Required_Argument, Options.Key_File); Opt_Config.Add_Option ("lower-hex", 'h', Getopt.No_Argument, Options.Lower_Hex_Output); Opt_Config.Add_Option ("raw", 'r', Getopt.No_Argument, Options.Raw_Output); Opt_Config.Add_Option