2424
2525namespace  py  =  pybind11;
2626using  namespace  bls ; 
27- using  std::vector;
2827
2928
3029PYBIND11_MODULE (blspy, m)
@@ -46,9 +45,10 @@ PYBIND11_MODULE(blspy, m)
4645                        " Length of bytes object not equal to PrivateKey::SIZE" 
4746                }
4847                auto  data_ptr = reinterpret_cast <const  uint8_t  *>(info.ptr );
49-                 std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
48+                 std::array<uint8_t , PrivateKey::PRIVATE_KEY_SIZE> data;
49+                 std::copy (data_ptr, data_ptr + PrivateKey::PRIVATE_KEY_SIZE, data.data ());
5050                py::gil_scoped_release release;
51-                 return  PrivateKey::FromByteVector  (data);
51+                 return  PrivateKey::FromBytes  (data);
5252            })
5353        .def (
5454            " __bytes__" 
@@ -355,9 +355,8 @@ PYBIND11_MODULE(blspy, m)
355355            return  G1Element ();
356356        }))
357357        .def (py::init (&G1Element::FromByteVector), py::call_guard<py::gil_scoped_release>())
358-         .def (py::init (&G1Element::FromByteVectorUnchecked), py::call_guard<py::gil_scoped_release>())
359358        .def (py::init ([](py::int_ pyint) {
360-             std::vector <uint8_t >  buffer ( G1Element::SIZE,  0 ) ;
359+             std::array <uint8_t ,  G1Element::SIZE> buffer{} ;
361360            if  (_PyLong_AsByteArray (
362361                    (PyLongObject *)pyint.ptr (),
363362                    buffer.data (),
@@ -367,7 +366,7 @@ PYBIND11_MODULE(blspy, m)
367366                throw  std::invalid_argument (" Failed to cast int to G1Element" 
368367            }
369368            py::gil_scoped_release release;
370-             return  G1Element::FromByteVector  (buffer);
369+             return  G1Element::FromBytes  (buffer);
371370        }))
372371        .def (py::init ([](py::buffer const  b) {
373372            py::buffer_info info = b.request ();
@@ -380,9 +379,10 @@ PYBIND11_MODULE(blspy, m)
380379                    " Length of bytes object not equal to G1Element::SIZE" 
381380            }
382381            auto  data_ptr = static_cast <uint8_t  *>(info.ptr );
383-             std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
382+             std::array<uint8_t , G1Element::SIZE> data;
383+             std::copy (data_ptr, data_ptr + G1Element::SIZE, data.data ());
384384            py::gil_scoped_release release;
385-             return  G1Element::FromByteVector  (data);
385+             return  G1Element::FromBytes  (data);
386386        }))
387387        .def (
388388            " from_bytes" 
@@ -397,9 +397,10 @@ PYBIND11_MODULE(blspy, m)
397397                        " Length of bytes object not equal to G1Element::SIZE" 
398398                }
399399                auto  data_ptr = reinterpret_cast <const  uint8_t  *>(info.ptr );
400-                 std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
400+                 std::array<uint8_t , G1Element::SIZE> data;
401+                 std::copy (data_ptr, data_ptr + G1Element::SIZE, data.data ());
401402                py::gil_scoped_release release;
402-                 return  G1Element::FromByteVector  (data);
403+                 return  G1Element::FromBytes  (data);
403404            })
404405        .def (
405406            " from_bytes_unchecked" 
@@ -414,9 +415,7 @@ PYBIND11_MODULE(blspy, m)
414415                      " Length of bytes object not equal to G1Element::SIZE" 
415416              }
416417              auto  data_ptr = reinterpret_cast <const  uint8_t  *>(info.ptr );
417-               std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
418-               py::gil_scoped_release release;
419-               return  G1Element::FromByteVectorUnchecked (data);
418+               return  G1Element::FromBytesUnchecked ({data_ptr, G1Element::SIZE});
420419            })
421420        .def (" generator" 
422421        .def (" from_message" const  std::vector<uint8_t >&, const  uint8_t *, int >(&G1Element::FromMessage), py::call_guard<py::gil_scoped_release>())
@@ -498,7 +497,6 @@ PYBIND11_MODULE(blspy, m)
498497            return  G2Element ();
499498        }))
500499        .def (py::init (&G2Element::FromByteVector), py::call_guard<py::gil_scoped_release>())
501-         .def (py::init (&G2Element::FromByteVectorUnchecked), py::call_guard<py::gil_scoped_release>())
502500        .def (py::init ([](py::buffer const  b) {
503501            py::buffer_info info = b.request ();
504502            if  (info.format  != py::format_descriptor<uint8_t >::format () ||
@@ -510,12 +508,13 @@ PYBIND11_MODULE(blspy, m)
510508                    " Length of bytes object not equal to G2Element::SIZE" 
511509            }
512510            auto  data_ptr = static_cast <uint8_t  *>(info.ptr );
513-             std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
511+             std::array<uint8_t , G2Element::SIZE> data;
512+             std::copy (data_ptr, data_ptr + G2Element::SIZE, data.data ());
514513            py::gil_scoped_release release;
515-             return  G2Element::FromByteVector  (data);
514+             return  G2Element::FromBytes  (data);
516515        }))
517516        .def (py::init ([](py::int_ pyint) {
518-             std::vector <uint8_t >  buffer ( G2Element::SIZE,  0 ) ;
517+             std::array <uint8_t ,  G2Element::SIZE> buffer{} ;
519518            if  (_PyLong_AsByteArray (
520519                    (PyLongObject *)pyint.ptr (),
521520                    buffer.data (),
@@ -525,7 +524,7 @@ PYBIND11_MODULE(blspy, m)
525524                throw  std::invalid_argument (" Failed to cast int to G2Element" 
526525            }
527526            py::gil_scoped_release release;
528-             return  G2Element::FromByteVector  (buffer);
527+             return  G2Element::FromBytes  (buffer);
529528        }))
530529        .def (
531530            " from_bytes" 
@@ -540,9 +539,10 @@ PYBIND11_MODULE(blspy, m)
540539                        " Length of bytes object not equal to G2Element::SIZE" 
541540                }
542541                auto  data_ptr = reinterpret_cast <const  uint8_t  *>(info.ptr );
543-                 std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
542+                 std::array<uint8_t , G2Element::SIZE> data;
543+                 std::copy (data_ptr, data_ptr + G2Element::SIZE, data.data ());
544544                py::gil_scoped_release release;
545-                 return  G2Element::FromByteVector  (data);
545+                 return  G2Element::FromBytes  (data);
546546            })
547547        .def (
548548            " from_bytes_unchecked" 
@@ -557,9 +557,7 @@ PYBIND11_MODULE(blspy, m)
557557                      " Length of bytes object not equal to G2Element::SIZE" 
558558              }
559559              auto  data_ptr = reinterpret_cast <const  uint8_t  *>(info.ptr );
560-               std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
561-               py::gil_scoped_release release;
562-               return  G2Element::FromByteVector (data);
560+               return  G2Element::FromBytesUnchecked ({data_ptr, G2Element::SIZE});
563561            })
564562        .def (" generator" 
565563        .def (" from_message" const  std::vector<uint8_t >&, const  uint8_t *, int >(&G2Element::FromMessage), py::call_guard<py::gil_scoped_release>())
@@ -642,12 +640,13 @@ PYBIND11_MODULE(blspy, m)
642640                    " Length of bytes object not equal to G2Element::SIZE" 
643641            }
644642            auto  data_ptr = static_cast <uint8_t  *>(info.ptr );
645-             std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
643+             std::array<uint8_t , GTElement::SIZE> data;
644+             std::copy (data_ptr, data_ptr + GTElement::SIZE, data.data ());
646645            py::gil_scoped_release release;
647-             return  GTElement::FromByteVector  (data);
646+             return  GTElement::FromBytes  (data);
648647        }))
649648        .def (py::init ([](py::int_ pyint) {
650-             std::vector <uint8_t >  buffer (GTElement ::SIZE,  0 ) ;
649+             std::array <uint8_t , G1Element ::SIZE> buffer{} ;
651650            if  (_PyLong_AsByteArray (
652651                    (PyLongObject *)pyint.ptr (),
653652                    buffer.data (),
@@ -657,7 +656,7 @@ PYBIND11_MODULE(blspy, m)
657656                throw  std::invalid_argument (" Failed to cast int to GTElement" 
658657            }
659658            py::gil_scoped_release release;
660-             return  GTElement::FromByteVector  (buffer);
659+             return  GTElement::FromBytes  (buffer);
661660        }))
662661        .def (
663662            " from_bytes" 
@@ -672,9 +671,10 @@ PYBIND11_MODULE(blspy, m)
672671                        " Length of bytes object not equal to GTElement::SIZE" 
673672                }
674673                auto  data_ptr = reinterpret_cast <const  uint8_t  *>(info.ptr );
675-                 std::vector<uint8_t > data (data_ptr, data_ptr + info.size );
674+                 std::array<uint8_t , GTElement::SIZE> data;
675+                 std::copy (data_ptr, data_ptr + GTElement::SIZE, data.data ());
676676                py::gil_scoped_release release;
677-                 return  GTElement::FromByteVector  (data);
677+                 return  GTElement::FromBytes  (data);
678678            })
679679        .def (" unity" 
680680        .def (py::self == py::self)
0 commit comments