1 /* 2 * hunt-proton: AMQP Protocol library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 13 module hunt.proton.codec.security.SaslChallengeType; 14 15 import hunt.collection.Collections; 16 import hunt.collection.List; 17 import hunt.proton.amqp.Binary; 18 import hunt.proton.amqp.Symbol; 19 import hunt.proton.amqp.UnsignedLong; 20 import hunt.proton.amqp.security.SaslChallenge; 21 import hunt.proton.codec.AbstractDescribedType; 22 import hunt.proton.codec.DecodeException; 23 import hunt.proton.codec.Decoder; 24 import hunt.proton.codec.DescribedTypeConstructor; 25 import hunt.proton.codec.EncoderImpl; 26 import hunt.logging; 27 import hunt.Object; 28 import std.concurrency : initOnce; 29 30 import hunt.Exceptions; 31 32 33 class SaslChallengeType : AbstractDescribedType!(SaslChallenge,List!Binary) , DescribedTypeConstructor!(SaslChallenge) 34 { 35 //private static Object[] DESCRIPTORS = 36 //{ 37 // UnsignedLong.valueOf(0x0000000000000042L), Symbol.valueOf("amqp:sasl-challenge:list"), 38 //}; 39 40 // private static UnsignedLong DESCRIPTOR = UnsignedLong.valueOf(0x0000000000000042L); 41 42 43 static Object[] DESCRIPTORS() { 44 __gshared Object[] inst; 45 return initOnce!inst([UnsignedLong.valueOf(0x0000000000000042L), Symbol.valueOf("amqp:sasl-challenge:list")]); 46 } 47 48 static UnsignedLong DESCRIPTOR() { 49 __gshared UnsignedLong inst; 50 return initOnce!inst(UnsignedLong.valueOf(0x0000000000000042L)); 51 } 52 53 54 55 this(EncoderImpl encoder) 56 { 57 super(encoder); 58 } 59 60 override 61 public UnsignedLong getDescriptor() 62 { 63 return DESCRIPTOR; 64 } 65 66 override 67 protected List!Binary wrap(SaslChallenge val) 68 { 69 return Collections.singletonList!Binary(val.getChallenge()); 70 } 71 72 73 74 public SaslChallenge newInstance(Object described) 75 { 76 List!Object l = cast(List!Object) described; 77 78 SaslChallenge o = new SaslChallenge(); 79 80 if(l.isEmpty()) 81 { 82 logError("The challenge field cannot be omitted"); 83 // throw new DecodeException("The challenge field cannot be omitted"); 84 } 85 86 o.setChallenge( cast(Binary) l.get( 0 ) ); 87 88 89 90 return o; 91 } 92 93 public TypeInfo getTypeClass() 94 { 95 return typeid(SaslChallenge); 96 } 97 98 99 100 static void register(Decoder decoder, EncoderImpl encoder) 101 { 102 SaslChallengeType type = new SaslChallengeType(encoder); 103 //implementationMissing(false); 104 foreach(Object descriptor ; DESCRIPTORS) 105 { 106 decoder.registerDynamic(descriptor, type); 107 } 108 encoder.register(type); 109 } 110 111 112 }