...

Source file src/github.com/lestrrat-go/jwx/jwe/options.go

Documentation: github.com/lestrrat-go/jwx/jwe

     1  package jwe
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/lestrrat-go/option"
     7  )
     8  
     9  type Option = option.Interface
    10  type identMessage struct{}
    11  type identPostParser struct{}
    12  type identPrettyFormat struct{}
    13  type identProtectedHeader struct{}
    14  
    15  type DecryptOption interface {
    16  	Option
    17  	decryptOption()
    18  }
    19  
    20  type decryptOption struct {
    21  	Option
    22  }
    23  
    24  func (*decryptOption) decryptOption() {}
    25  
    26  type SerializerOption interface {
    27  	Option
    28  	serializerOption()
    29  }
    30  
    31  type serializerOption struct {
    32  	Option
    33  }
    34  
    35  func (*serializerOption) serializerOption() {}
    36  
    37  type EncryptOption interface {
    38  	Option
    39  	encryptOption()
    40  }
    41  
    42  type encryptOption struct {
    43  	Option
    44  }
    45  
    46  func (*encryptOption) encryptOption() {}
    47  
    48  // WithPrettyFormat specifies if the `jwe.JSON` serialization tool
    49  // should generate pretty-formatted output
    50  func WithPrettyFormat(b bool) SerializerOption {
    51  	return &serializerOption{option.New(identPrettyFormat{}, b)}
    52  }
    53  
    54  // Specify contents of the protected header. Some fields such as
    55  // "enc" and "zip" will be overwritten when encryption is performed.
    56  func WithProtectedHeaders(h Headers) EncryptOption {
    57  	cloned, _ := h.Clone(context.Background())
    58  	return &encryptOption{option.New(identProtectedHeader{}, cloned)}
    59  }
    60  
    61  // WithMessage provides a message object to be populated by `jwe.Decrpt`
    62  // Using this option allows you to decrypt AND obtain the `jwe.Message`
    63  // in one go.
    64  //
    65  // Note that you should NOT be using the message object for anything other
    66  // than inspecting its contents. Particularly, do not expect the message
    67  // reliable when you call `Decrypt` on it. `(jwe.Message).Decrypt` is
    68  // slated to be deprecated in the next major version.
    69  func WithMessage(m *Message) DecryptOption {
    70  	return &decryptOption{option.New(identMessage{}, m)}
    71  }
    72  
    73  // WithPostParser specifies the handler to be called immediately
    74  // after the JWE message has been parsed, but before decryption
    75  // takes place during `jwe.Decrypt`.
    76  //
    77  // This option exists to allow advanced users that require the use
    78  // of information stored in the JWE message to determine how the
    79  // decryption should be handled.
    80  //
    81  // For security reasons it is highly recommended that you thoroughly
    82  // study how the process works before using this option. This is especially
    83  // true if you are trying to infer key algorithms and keys to use to
    84  // decrypt a message using non-standard hints.
    85  func WithPostParser(p PostParser) DecryptOption {
    86  	return &decryptOption{option.New(identPostParser{}, p)}
    87  }
    88  

View as plain text