import { encode , types , decode } from "binary-data" ; import { HandshakeType } from "../../const" ; import { ClientCertificateType , DistinguishedName , SignatureAlgorithm , } from "../../binary" ; import { Handshake } from "../../../typings/domain" ; import { FragmentedHandshake } from "../../../record/message/fragment" ; export class ServerCertificateRequest implements Handshake { msgType = HandshakeType . certificate_request ; messageSeq ? : number ; static readonly spec = { certificateTypes : types . array ( ClientCertificateType , types . uint8 , "bytes" ) , signatures : types . array ( SignatureAlgorithm , types . uint16be , "bytes" ) , authorities : types . array ( DistinguishedName , types . uint16be , "bytes" ) , } ; constructor ( public certificateTypes , public signatures , public authorities ) { } static createEmpty ( ) { return new ServerCertificateRequest ( undefined as any , undefined as any , undefined as any ) ; } static deSerialize ( buf ) { return new ServerCertificateRequest ( ... Object . values ( decode ( buf , ServerCertificateRequest . spec ) ) ) ; } serialize ( ) { const res = encode ( this , ServerCertificateRequest . spec ) . slice ( ) ; return Buffer . from ( res ) ; } toFragment ( ) { const body = this . serialize ( ) ; return new FragmentedHandshake ( this . msgType , body . length , this . messageSeq ! , 0 , body . length , body ) ; } }