NewKeyValue returns a KeyValue as defined by cfg. It returns an error of type NeedWipeError when the returned KeyValue should be fixed with Wipe.
(cfg jsonconfig.Obj)
| 226 | // It returns an error of type NeedWipeError when the returned KeyValue should |
| 227 | // be fixed with Wipe. |
| 228 | func NewKeyValue(cfg jsonconfig.Obj) (KeyValue, error) { |
| 229 | var s KeyValue |
| 230 | var err error |
| 231 | typ := cfg.RequiredString("type") |
| 232 | ctor, ok := ctors[typ] |
| 233 | if typ != "" && !ok { |
| 234 | return nil, fmt.Errorf("Invalid sorted.KeyValue type %q", typ) |
| 235 | } |
| 236 | if ok { |
| 237 | s, err = ctor(cfg) |
| 238 | if err != nil { |
| 239 | we, ok := err.(NeedWipeError) |
| 240 | if !ok { |
| 241 | return nil, fmt.Errorf("error from %q KeyValue: %v", typ, err) |
| 242 | } |
| 243 | if err := cfg.Validate(); err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | we.Msg = fmt.Sprintf("error from %q KeyValue: %v", typ, err) |
| 247 | return s, we |
| 248 | } |
| 249 | } |
| 250 | return s, cfg.Validate() |
| 251 | } |
| 252 | |
| 253 | // NewKeyValueMaybeWipe calls NewKeyValue and wipes the KeyValue if, and only |
| 254 | // if, NewKeyValue has returned a NeedWipeError. |
no outgoing calls