Class: EchSpec::CLI::GenConfigs
- Inherits:
-
Object
- Object
- EchSpec::CLI::GenConfigs
- Defined in:
- lib/echspec/cli/gen_configs.rb
Instance Method Summary collapse
Instance Method Details
#execute(argv) ⇒ Object
4 5 6 7 |
# File 'lib/echspec/cli/gen_configs.rb', line 4 def execute(argv) fpath = (argv) write(fpath) end |
#parse_options(argv) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/echspec/cli/gen_configs.rb', line 9 def (argv) op = OptionParser.new op. = <<~USAGE Usage: echspec gen_configs {FILE} Generate an ECHConfig PEM file. Examples: $ echspec gen_configs echconfigs.pem USAGE begin args = op.parse(argv) rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e warn op warn "** #{e.}" exit 1 end if args.length != 1 warn op warn '** {FILE} argument is not specified' exit 1 end args[0] end |
#write(fpath) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/echspec/cli/gen_configs.rb', line 38 def write(fpath) hostname = 'localhost' key = OpenSSL::PKey.generate_key('X25519') echconfigs = ECHConfigList.new( [ ECHConfig.new( "\xfe\x0d".b, ECHConfig::ECHConfigContents.new( ECHConfig::ECHConfigContents::HpkeKeyConfig.new( 123, ECHConfig::ECHConfigContents::HpkeKeyConfig::HpkeKemId.new(HPKE::DHKEM_X25519_HKDF_SHA256), ECHConfig::ECHConfigContents::HpkeKeyConfig::HpkePublicKey.new(key.raw_public_key), [ ECHConfig::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite.new( ECHConfig::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite::HpkeKdfId.new(HPKE::HKDF_SHA256), ECHConfig::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite::HpkeAeadId.new(HPKE::AES_128_GCM) ) ] ), 32, hostname.b, ECHConfig::ECHConfigContents::Extensions.new('') ) ) ] ) File.write(fpath, key.private_to_pem + echconfigs.to_pem) end |