LCB Woes

Brian Milby brian at milby7.com
Thu Apr 12 22:52:46 EDT 2018


Here's an snip from my libSodium start:

private __safe foreign handler \
MCDataCreateWithBytesAndRelease( \
in pBytes as Pointer, \
in pCount as LCUIndex, \
out rData as Data) \
returns CBool binds to "<builtin>"

private __safe foreign handler \
MCMemoryAllocate( \
in pSize as LCUIndex, \
out rBlock as Pointer) \
returns CBool binds to "<builtin>"

private __safe foreign handler \
MCMemoryDeallocate( \
in pBlock as Pointer) \
returns nothing binds to "<builtin>"

constant kCrypto_kx_PUBLICKEYBYTES is 32
constant kCrypto_kx_SECRETKEYBYTES is 32

private foreign handler \
_crypto_kx_keypair( \
in pPK as Pointer, /* unsigned char pk[crypto_kx_PUBLICKEYBYTES] */ \
in pSK as Pointer) /* unsigned char sk[crypto_kx_SECRETKEYBYTES] */ \
returns CInt binds to "c:libsodium>crypto_kx_keypair"

public handler sodiumKxKeypair(out rPK as Data, out rSK as Data) returns
Boolean
variable tPKbuffer as Pointer
variable tSKbuffer as Pointer

if not MCMemoryAllocate(kCrypto_kx_PUBLICKEYBYTES, tPKbuffer) then
throw "can't allocate PK buffer"
end if
if not MCMemoryAllocate(kCrypto_kx_SECRETKEYBYTES, tSKbuffer) then
MCMemoryDeallocate(tPKbuffer)
throw "can't allocate SK buffer"
end if
unsafe
if _crypto_kx_keypair(tPKbuffer, tSKbuffer) < 0 then
MCMemoryDeallocate(tPKbuffer)
MCMemoryDeallocate(tSKbuffer)
throw "could not get keys"
end if
end unsafe

if not MCDataCreateWithBytesAndRelease(tPKbuffer, \
kCrypto_kx_PUBLICKEYBYTES, rPK) then
MCMemoryDeallocate(tPKbuffer)
MCMemoryDeallocate(tSKbuffer)
throw "error copying PK"
end if
if not MCDataCreateWithBytesAndRelease(tSKbuffer, \
kCrypto_kx_SECRETKEYBYTES, rSK) then
MCMemoryDeallocate(tSKbuffer)
throw "error copying SK"
end if

return true
end handler


On Thu, Apr 12, 2018 at 9:37 PM, Pi Digital via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Why on earth would you have to type them? Why not for loop them or
> copy-paste or get LC to give you a 1024 char string of them you can
> copy-paste in? Odd.
>
> LCB is very much in its youth especially for java and objc. We have only
> the bare minimum of examples and tutorials and documentation of course.
> Building a library is very similar to widgets with the exception that they
> are not linked to a gui control or display. So they just handle calls and
> functions but don’t have an object/control on the card and thus no property
> dialogue either. The examples for widgets work practically the same for a
> library. But there will be occasional differences you’ll come across as you
> go. No doubt Ali will be providing some more info on these in time. But
> start digging into it now. I’m still playing around trying to make some
> libraries of my own - simple ones to start with.
>
> All the best.
>
> Sean Cole
> Pi Digital
>
> > On 13 Apr 2018, at 03:04, Mark Wieder via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> >
> >> On 04/12/2018 06:03 PM, Brian Milby via use-livecode wrote:
> >> What language is the library written in? Which platform? I have some
> code
> >> that I’ve started to put together for libSodium, but I have not done
> much
> >> more than reference the calls.
> >
> > Interesting. I started down the libSodium path and gave it up when I
> found that I had to create a struct with 1024 individual byte references
> for an embedded buffer. There really should be a way to specify a number so
> you don't have to type 1024 "h" characters in a row.
> >
> > --
> > Mark Wieder
> > ahsoftware at gmail.com
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the Use-livecode mailing list